Handle single long words that exceed the wrap column in autoflow

This commit is contained in:
Nathan Sobo
2013-01-10 17:21:23 -07:00
parent b0fe034c9a
commit b307bcc0de
2 changed files with 19 additions and 5 deletions

View File

@@ -14,10 +14,12 @@ module.exports =
currentLine = []
currentLineLength = 0
for segment in @segmentText(text.replace(/\n/g, ' '))
if /\w/.test(segment) and currentLineLength + segment.length > wrapColumn
lines.push(currentLine.join(''))
currentLine = []
currentLineLength = 0
if /\w/.test(segment) and
(currentLineLength + segment.length > wrapColumn) and
(currentLineLength > 0 or segment.length < wrapColumn)
lines.push(currentLine.join(''))
currentLine = []
currentLineLength = 0
currentLine.push(segment)
currentLineLength += segment.length
lines.push(currentLine.join(''))

View File

@@ -7,10 +7,10 @@ describe "Autoflow package", ->
rootView = new RootView
atom.loadPackage 'autoflow'
editor = rootView.getActiveEditor()
config.set('editor.preferredLineLength', 30)
describe "autoflow:reflow-paragraph", ->
it "rearranges line breaks in the current paragraph to ensure lines are shorter than config.editor.preferredLineLength", ->
config.set('editor.preferredLineLength', 30)
editor.setText """
This is a preceding paragraph, which shouldn't be modified by a reflow of the following paragraph.
@@ -39,3 +39,15 @@ describe "Autoflow package", ->
This is a following paragraph, which shouldn't be modified by a reflow of the preciding paragraph.
"""
it "allows for single words that exceed the preferred wrap column length", ->
editor.setText("this-is-a-super-long-word-that-shouldn't-break-autoflow and these are some smaller words")
editor.setCursorBufferPosition([0, 4])
editor.trigger 'autoflow:reflow-paragraph'
expect(editor.getText()).toBe """
this-is-a-super-long-word-that-shouldn't-break-autoflow
and these are some smaller
words
"""