From b307bcc0de9e41ae6c8da32d0a248885d1d5d8e5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 10 Jan 2013 17:21:23 -0700 Subject: [PATCH] Handle single long words that exceed the wrap column in autoflow --- src/packages/autoflow/lib/autoflow.coffee | 10 ++++++---- src/packages/autoflow/spec/autoflow-spec.coffee | 14 +++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/packages/autoflow/lib/autoflow.coffee b/src/packages/autoflow/lib/autoflow.coffee index 41a583e68..a1dc9f73b 100644 --- a/src/packages/autoflow/lib/autoflow.coffee +++ b/src/packages/autoflow/lib/autoflow.coffee @@ -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('')) diff --git a/src/packages/autoflow/spec/autoflow-spec.coffee b/src/packages/autoflow/spec/autoflow-spec.coffee index d41e25bb1..206172843 100644 --- a/src/packages/autoflow/spec/autoflow-spec.coffee +++ b/src/packages/autoflow/spec/autoflow-spec.coffee @@ -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 + """