Add editor.softWrapAtPreferredLineLength config setting

This is used by the DisplayBuffer to use `editor.preferredLineLength`
as the soft wrap column instead of the editor size.
This commit is contained in:
Kevin Sawicki
2013-08-22 19:31:32 -07:00
parent 8f193e4fb5
commit a45b93614e
3 changed files with 18 additions and 0 deletions

View File

@@ -65,6 +65,21 @@ describe "DisplayBuffer", ->
changeHandler.reset()
describe "rendering of soft-wrapped lines", ->
describe "when editor.softWrapAtPreferredLineLength is set", ->
it "uses the preferred line length as the soft wrap column when it is less than the configured soft wrap column", ->
config.set('editor.preferredLineLength', 100)
config.set('editor.softWrapAtPreferredLineLength', true)
displayBuffer.updateWrappedScreenLines()
expect(displayBuffer.lineForRow(10).text).toBe ' return '
config.set('editor.preferredLineLength', 5)
displayBuffer.updateWrappedScreenLines()
expect(displayBuffer.lineForRow(10).text).toBe 'funct'
config.set('editor.softWrapAtPreferredLineLength', false)
displayBuffer.updateWrappedScreenLines()
expect(displayBuffer.lineForRow(10).text).toBe ' return '
describe "when the line is shorter than the max line length", ->
it "renders the line unchanged", ->
expect(displayBuffer.lineForRow(0).text).toBe buffer.lineForRow(0)

View File

@@ -415,6 +415,8 @@ class DisplayBuffer
# Returns a {Number} representing the `line` position where the wrap would take place.
# Returns `null` if a wrap wouldn't occur.
findWrapColumn: (line, softWrapColumn=@getSoftWrapColumn()) ->
if config.get('editor.softWrapAtPreferredLineLength')
softWrapColumn = Math.min(softWrapColumn, config.getPositiveInt('editor.preferredLineLength', softWrapColumn))
return unless @getSoftWrap()
return unless line.length > softWrapColumn

View File

@@ -26,6 +26,7 @@ class Editor extends View
tabLength: 2
softWrap: false
softTabs: true
softWrapAtPreferredLineLength: false
@nextEditorId: 1