Skip to content

Commit 7f7bdbf

Browse files
authored
Merge pull request atom#14495 from warrenpnz/maxScreenLineLength
Enable MAX_SCREEN_LINE_LENGTH to now be set via a config option
2 parents 9141051 + 0b55d4e commit 7f7bdbf

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

spec/text-editor-registry-spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,21 @@ describe('TextEditorRegistry', function () {
544544
expect(editor.getSoftWrapColumn()).toBe(80)
545545
})
546546

547+
it('allows for custom definition of maximum soft wrap based on config', async function () {
548+
editor.update({
549+
softWrapped: false,
550+
maxScreenLineLength: 1500,
551+
})
552+
553+
expect(editor.getSoftWrapColumn()).toBe(1500)
554+
555+
atom.config.set('editor.softWrap', false)
556+
atom.config.set('editor.maxScreenLineLength', 500)
557+
registry.maintainConfig(editor)
558+
await initialPackageActivation
559+
expect(editor.getSoftWrapColumn()).toBe(500)
560+
})
561+
547562
it('sets the preferred line length based on the config', async function () {
548563
editor.update({preferredLineLength: 80})
549564
expect(editor.getPreferredLineLength()).toBe(80)

spec/text-editor-spec.coffee

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe "TextEditor", ->
7474
expect(editor2.getInvisibles()).toEqual(editor.getInvisibles())
7575
expect(editor2.getEditorWidthInChars()).toBe(editor.getEditorWidthInChars())
7676
expect(editor2.displayLayer.tabLength).toBe(editor2.getTabLength())
77+
expect(editor2.displayLayer.softWrapColumn).toBe(editor2.getSoftWrapColumn())
7778

7879
describe "when the editor is constructed with the largeFileMode option set to true", ->
7980
it "loads the editor but doesn't tokenize", ->
@@ -145,7 +146,7 @@ describe "TextEditor", ->
145146
returnedPromise = editor.update({
146147
tabLength: 6, softTabs: false, softWrapped: true, editorWidthInChars: 40,
147148
showInvisibles: false, mini: false, lineNumberGutterVisible: false, scrollPastEnd: true,
148-
autoHeight: false
149+
autoHeight: false, maxScreenLineLength: 1000
149150
})
150151

151152
expect(returnedPromise).toBe(element.component.getNextUpdatePromise())
@@ -5918,3 +5919,11 @@ describe "TextEditor", ->
59185919
describe "::getElement", ->
59195920
it "returns an element", ->
59205921
expect(editor.getElement() instanceof HTMLElement).toBe(true)
5922+
5923+
describe 'setMaxScreenLineLength', ->
5924+
it "sets the maximum line length in the editor before soft wrapping is forced", ->
5925+
expect(editor.getSoftWrapColumn()).toBe(500)
5926+
editor.update({
5927+
maxScreenLineLength: 1500
5928+
})
5929+
expect(editor.getSoftWrapColumn()).toBe(1500)

src/config-schema.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ const configSchema = {
409409
minimum: 1,
410410
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.'
411411
},
412+
maxScreenLineLength: {
413+
type: 'integer',
414+
default: 500,
415+
minimum: 500,
416+
description: 'Defines the maximum width of the editor window before soft wrapping is enforced, in number of characters.'
417+
},
412418
tabLength: {
413419
type: 'integer',
414420
default: 2,

src/text-editor-registry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const EDITOR_PARAMS_BY_SETTING_KEY = [
1818
['editor.softWrapHangingIndent', 'softWrapHangingIndentLength'],
1919
['editor.softWrapAtPreferredLineLength', 'softWrapAtPreferredLineLength'],
2020
['editor.preferredLineLength', 'preferredLineLength'],
21+
['editor.maxScreenLineLength', 'maxScreenLineLength'],
2122
['editor.autoIndent', 'autoIndent'],
2223
['editor.autoIndentOnPaste', 'autoIndentOnPaste'],
2324
['editor.scrollPastEnd', 'scrollPastEnd'],

src/text-editor.coffee

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ TextEditorElement = null
1717
{isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter, isWrapBoundary} = require './text-utils'
1818

1919
ZERO_WIDTH_NBSP = '\ufeff'
20-
MAX_SCREEN_LINE_LENGTH = 500
2120

2221
# Essential: This class represents all essential editing state for a single
2322
# {TextBuffer}, including cursor and selection positions, folds, and soft wraps.
@@ -158,7 +157,7 @@ class TextEditor extends Model
158157
@assert, grammar, @showInvisibles, @autoHeight, @autoWidth, @scrollPastEnd, @scrollSensitivity, @editorWidthInChars,
159158
@tokenizedBuffer, @displayLayer, @invisibles, @showIndentGuide,
160159
@softWrapped, @softWrapAtPreferredLineLength, @preferredLineLength,
161-
@showCursorOnSelection
160+
@showCursorOnSelection, @maxScreenLineLength
162161
} = params
163162

164163
@assert ?= (condition) -> condition
@@ -183,6 +182,7 @@ class TextEditor extends Model
183182
@softWrapped ?= false
184183
@softWrapAtPreferredLineLength ?= false
185184
@preferredLineLength ?= 80
185+
@maxScreenLineLength ?= 500
186186
@showLineNumbers ?= true
187187

188188
@buffer ?= new TextBuffer({
@@ -323,6 +323,11 @@ class TextEditor extends Model
323323
@preferredLineLength = value
324324
displayLayerParams.softWrapColumn = @getSoftWrapColumn()
325325

326+
when 'maxScreenLineLength'
327+
if value isnt @maxScreenLineLength
328+
@maxScreenLineLength = value
329+
displayLayerParams.softWrapColumn = @getSoftWrapColumn()
330+
326331
when 'mini'
327332
if value isnt @mini
328333
@mini = value
@@ -433,7 +438,7 @@ class TextEditor extends Model
433438
softWrapHangingIndentLength: @displayLayer.softWrapHangingIndent
434439

435440
@id, @softTabs, @softWrapped, @softWrapAtPreferredLineLength,
436-
@preferredLineLength, @mini, @editorWidthInChars, @width, @largeFileMode,
441+
@preferredLineLength, @mini, @editorWidthInChars, @width, @largeFileMode, @maxScreenLineLength,
437442
@registered, @invisibles, @showInvisibles, @showIndentGuide, @autoHeight, @autoWidth
438443
}
439444

@@ -3039,7 +3044,7 @@ class TextEditor extends Model
30393044
else
30403045
@getEditorWidthInChars()
30413046
else
3042-
MAX_SCREEN_LINE_LENGTH
3047+
@maxScreenLineLength
30433048

30443049
###
30453050
Section: Indentation

0 commit comments

Comments
 (0)