From ce99d401c28cea3088c178169c47943aa006e38b Mon Sep 17 00:00:00 2001 From: Warren Powell Date: Fri, 19 May 2017 15:55:52 +1200 Subject: [PATCH 1/4] Enables MAX_SCREEN_LINE_LENGTH to now be set via a config option in editor settings. Defaults to 500 --- src/config-schema.js | 6 ++++++ src/text-editor-registry.js | 1 + 2 files changed, 7 insertions(+) diff --git a/src/config-schema.js b/src/config-schema.js index fb0164766..00fb8bbe3 100644 --- a/src/config-schema.js +++ b/src/config-schema.js @@ -409,6 +409,12 @@ const configSchema = { minimum: 1, description: 'Identifies the length of a line which is used when wrapping text with the `Soft Wrap At Preferred Line Length` setting enabled, in number of characters.' }, + maxScreenLineLength: { + type: 'integer', + default: 500, + minimum: 500, + description: 'Defines the maximum width of the editor window before soft wrapping is enforced, in number of characters.' + }, tabLength: { type: 'integer', default: 2, diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index 72aa8b364..35be27fd1 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -18,6 +18,7 @@ const EDITOR_PARAMS_BY_SETTING_KEY = [ ['editor.softWrapHangingIndent', 'softWrapHangingIndentLength'], ['editor.softWrapAtPreferredLineLength', 'softWrapAtPreferredLineLength'], ['editor.preferredLineLength', 'preferredLineLength'], + ['editor.maxScreenLineLength', 'maxScreenLineLength'], ['editor.autoIndent', 'autoIndent'], ['editor.autoIndentOnPaste', 'autoIndentOnPaste'], ['editor.scrollPastEnd', 'scrollPastEnd'], From a73f68c0dd3cf4d244457262940f812bf1a3ecea Mon Sep 17 00:00:00 2001 From: Warren Powell Date: Wed, 24 May 2017 15:43:50 +1200 Subject: [PATCH 2/4] Spec test for setMaxScreenLineLength --- spec/text-editor-spec.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index ec4a96359..efe023a21 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -5918,3 +5918,12 @@ describe "TextEditor", -> describe "::getElement", -> it "returns an element", -> expect(editor.getElement() instanceof HTMLElement).toBe(true) + + describe 'setMaxScreenLineLength', -> + it "sets the maximum line length in the editor before soft wrapping is forced", -> + expect(editor.maxScreenLineLength()).toBe 500 + editor.update({ + maxScreenLineLength: 1500 + }) + expect(editor.maxScreenLineLength()).toBe 1500 + From f2bb941a51cef395e5ff5a52933448d7c47e85ff Mon Sep 17 00:00:00 2001 From: wpowell-oss Date: Tue, 12 Sep 2017 13:51:57 +1200 Subject: [PATCH 3/4] Rebase to github/master --- spec/text-editor-spec.coffee | 9 --------- src/config-schema.js | 6 ------ src/text-editor-registry.js | 1 - 3 files changed, 16 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index efe023a21..ec4a96359 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -5918,12 +5918,3 @@ describe "TextEditor", -> describe "::getElement", -> it "returns an element", -> expect(editor.getElement() instanceof HTMLElement).toBe(true) - - describe 'setMaxScreenLineLength', -> - it "sets the maximum line length in the editor before soft wrapping is forced", -> - expect(editor.maxScreenLineLength()).toBe 500 - editor.update({ - maxScreenLineLength: 1500 - }) - expect(editor.maxScreenLineLength()).toBe 1500 - diff --git a/src/config-schema.js b/src/config-schema.js index 00fb8bbe3..fb0164766 100644 --- a/src/config-schema.js +++ b/src/config-schema.js @@ -409,12 +409,6 @@ const configSchema = { minimum: 1, description: 'Identifies the length of a line which is used when wrapping text with the `Soft Wrap At Preferred Line Length` setting enabled, in number of characters.' }, - maxScreenLineLength: { - type: 'integer', - default: 500, - minimum: 500, - description: 'Defines the maximum width of the editor window before soft wrapping is enforced, in number of characters.' - }, tabLength: { type: 'integer', default: 2, diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index 35be27fd1..72aa8b364 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -18,7 +18,6 @@ const EDITOR_PARAMS_BY_SETTING_KEY = [ ['editor.softWrapHangingIndent', 'softWrapHangingIndentLength'], ['editor.softWrapAtPreferredLineLength', 'softWrapAtPreferredLineLength'], ['editor.preferredLineLength', 'preferredLineLength'], - ['editor.maxScreenLineLength', 'maxScreenLineLength'], ['editor.autoIndent', 'autoIndent'], ['editor.autoIndentOnPaste', 'autoIndentOnPaste'], ['editor.scrollPastEnd', 'scrollPastEnd'], From 0b55d4e144a99ef63679fe4c7951e0fa4a957796 Mon Sep 17 00:00:00 2001 From: wpowell-oss Date: Tue, 12 Sep 2017 14:38:29 +1200 Subject: [PATCH 4/4] maxScreenLineLength rebased to github --- spec/text-editor-registry-spec.js | 15 +++++++++++++++ spec/text-editor-spec.coffee | 11 ++++++++++- src/config-schema.js | 6 ++++++ src/text-editor-registry.js | 1 + src/text-editor.coffee | 13 +++++++++---- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/spec/text-editor-registry-spec.js b/spec/text-editor-registry-spec.js index 2479bff9b..017ef1f1b 100644 --- a/spec/text-editor-registry-spec.js +++ b/spec/text-editor-registry-spec.js @@ -544,6 +544,21 @@ describe('TextEditorRegistry', function () { expect(editor.getSoftWrapColumn()).toBe(80) }) + it('allows for custom definition of maximum soft wrap based on config', async function () { + editor.update({ + softWrapped: false, + maxScreenLineLength: 1500, + }) + + expect(editor.getSoftWrapColumn()).toBe(1500) + + atom.config.set('editor.softWrap', false) + atom.config.set('editor.maxScreenLineLength', 500) + registry.maintainConfig(editor) + await initialPackageActivation + expect(editor.getSoftWrapColumn()).toBe(500) + }) + it('sets the preferred line length based on the config', async function () { editor.update({preferredLineLength: 80}) expect(editor.getPreferredLineLength()).toBe(80) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index ec4a96359..47b85bf1f 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -74,6 +74,7 @@ describe "TextEditor", -> expect(editor2.getInvisibles()).toEqual(editor.getInvisibles()) expect(editor2.getEditorWidthInChars()).toBe(editor.getEditorWidthInChars()) expect(editor2.displayLayer.tabLength).toBe(editor2.getTabLength()) + expect(editor2.displayLayer.softWrapColumn).toBe(editor2.getSoftWrapColumn()) describe "when the editor is constructed with the largeFileMode option set to true", -> it "loads the editor but doesn't tokenize", -> @@ -145,7 +146,7 @@ describe "TextEditor", -> returnedPromise = editor.update({ tabLength: 6, softTabs: false, softWrapped: true, editorWidthInChars: 40, showInvisibles: false, mini: false, lineNumberGutterVisible: false, scrollPastEnd: true, - autoHeight: false + autoHeight: false, maxScreenLineLength: 1000 }) expect(returnedPromise).toBe(element.component.getNextUpdatePromise()) @@ -5918,3 +5919,11 @@ describe "TextEditor", -> describe "::getElement", -> it "returns an element", -> expect(editor.getElement() instanceof HTMLElement).toBe(true) + + describe 'setMaxScreenLineLength', -> + it "sets the maximum line length in the editor before soft wrapping is forced", -> + expect(editor.getSoftWrapColumn()).toBe(500) + editor.update({ + maxScreenLineLength: 1500 + }) + expect(editor.getSoftWrapColumn()).toBe(1500) diff --git a/src/config-schema.js b/src/config-schema.js index fb0164766..00fb8bbe3 100644 --- a/src/config-schema.js +++ b/src/config-schema.js @@ -409,6 +409,12 @@ const configSchema = { minimum: 1, description: 'Identifies the length of a line which is used when wrapping text with the `Soft Wrap At Preferred Line Length` setting enabled, in number of characters.' }, + maxScreenLineLength: { + type: 'integer', + default: 500, + minimum: 500, + description: 'Defines the maximum width of the editor window before soft wrapping is enforced, in number of characters.' + }, tabLength: { type: 'integer', default: 2, diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index 72aa8b364..35be27fd1 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -18,6 +18,7 @@ const EDITOR_PARAMS_BY_SETTING_KEY = [ ['editor.softWrapHangingIndent', 'softWrapHangingIndentLength'], ['editor.softWrapAtPreferredLineLength', 'softWrapAtPreferredLineLength'], ['editor.preferredLineLength', 'preferredLineLength'], + ['editor.maxScreenLineLength', 'maxScreenLineLength'], ['editor.autoIndent', 'autoIndent'], ['editor.autoIndentOnPaste', 'autoIndentOnPaste'], ['editor.scrollPastEnd', 'scrollPastEnd'], diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 0eb0b1dee..f0b7f7f52 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -17,7 +17,6 @@ TextEditorElement = null {isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter, isWrapBoundary} = require './text-utils' ZERO_WIDTH_NBSP = '\ufeff' -MAX_SCREEN_LINE_LENGTH = 500 # Essential: This class represents all essential editing state for a single # {TextBuffer}, including cursor and selection positions, folds, and soft wraps. @@ -158,7 +157,7 @@ class TextEditor extends Model @assert, grammar, @showInvisibles, @autoHeight, @autoWidth, @scrollPastEnd, @scrollSensitivity, @editorWidthInChars, @tokenizedBuffer, @displayLayer, @invisibles, @showIndentGuide, @softWrapped, @softWrapAtPreferredLineLength, @preferredLineLength, - @showCursorOnSelection + @showCursorOnSelection, @maxScreenLineLength } = params @assert ?= (condition) -> condition @@ -183,6 +182,7 @@ class TextEditor extends Model @softWrapped ?= false @softWrapAtPreferredLineLength ?= false @preferredLineLength ?= 80 + @maxScreenLineLength ?= 500 @showLineNumbers ?= true @buffer ?= new TextBuffer({ @@ -323,6 +323,11 @@ class TextEditor extends Model @preferredLineLength = value displayLayerParams.softWrapColumn = @getSoftWrapColumn() + when 'maxScreenLineLength' + if value isnt @maxScreenLineLength + @maxScreenLineLength = value + displayLayerParams.softWrapColumn = @getSoftWrapColumn() + when 'mini' if value isnt @mini @mini = value @@ -433,7 +438,7 @@ class TextEditor extends Model softWrapHangingIndentLength: @displayLayer.softWrapHangingIndent @id, @softTabs, @softWrapped, @softWrapAtPreferredLineLength, - @preferredLineLength, @mini, @editorWidthInChars, @width, @largeFileMode, + @preferredLineLength, @mini, @editorWidthInChars, @width, @largeFileMode, @maxScreenLineLength, @registered, @invisibles, @showInvisibles, @showIndentGuide, @autoHeight, @autoWidth } @@ -3039,7 +3044,7 @@ class TextEditor extends Model else @getEditorWidthInChars() else - MAX_SCREEN_LINE_LENGTH + @maxScreenLineLength ### Section: Indentation