From 62cf65e7a96e1e4d5a13168e125df594ea13147c Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 9 Feb 2012 10:44:25 -0800 Subject: [PATCH] Token with interstitial whitespace is split before LineWrapper.maxLength --- spec/atom/line-wrapper-spec.coffee | 22 +++++++++++++++------- src/atom/line-wrapper.coffee | 5 +++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/spec/atom/line-wrapper-spec.coffee b/spec/atom/line-wrapper-spec.coffee index ac23f40c0..950a72bc4 100644 --- a/spec/atom/line-wrapper-spec.coffee +++ b/spec/atom/line-wrapper-spec.coffee @@ -71,14 +71,13 @@ fdescribe "LineWrapper", -> expect(event.newRange).toEqual(new Range([2, 4], [3, 6])) describe "when the update causes the line to wrap multiple times", -> - xit "updates tokens for the corresponding screen lines and emits a change event", -> + it "updates tokens for the corresponding screen lines and emits a change event", -> console.log '!!!!!!!!!!!!!!!!!!!!!!!!!!!' - buffer.insert([2, 4], ["/*",longText, longText, longText, longText, "*/"].join(' ')) - expect(tokensText(wrapper.tokensForScreenRow(2))).toBe ' 0123456789ABCDEF 0123456789ABCDEF ' - # expect(tokensText(wrapper.tokensForScreenRow(3))).toBe '0123456789ABCDEF 0123456789ABCDEF if (items.length ' - # expect(tokensText(wrapper.tokensForScreenRow(4))).toBe '<= 1) return items;' - # expect(tokensText(wrapper.tokensForScreenRow(3))).toBe 'items;' - # expect(tokensText(wrapper.tokensForScreenRow(4))).toBe ' var pivot = items.shift(), current, left = [], ' + buffer.insert([2, 4], ["/*", longText, longText, longText, longText, "*/"].join(' ')) + expect(tokensText(wrapper.tokensForScreenRow(2))).toBe ' /* 0123456789ABCDEF 0123456789ABCDEF ' + expect(tokensText(wrapper.tokensForScreenRow(3))).toBe '0123456789ABCDEF 0123456789ABCDEF */if (items.' + expect(tokensText(wrapper.tokensForScreenRow(4))).toBe 'length <= 1) return items;' + expect(tokensText(wrapper.tokensForScreenRow(5))).toBe ' var pivot = items.shift(), current, left = [], ' # expect(changeHandler).toHaveBeenCalled() # [event] = changeHandler.argsForCall[0] @@ -205,6 +204,15 @@ fdescribe "LineWrapper", -> expect(line1).toEqual [{value: '123'}, {value: '456'}, {value: 'a b ', type: 'foo'}] expect(line2).toEqual [{value: 'de', type: 'foo'}, {value: 'ghi'}] + describe "when the token is greater than max line length and has interstitial whitespace preceding the max line length", -> + it "splits the token at the first word boundary following the max line length", -> + screenLines = wrapper.splitTokens [{value: "01234 67891234 6789", type: 1}] + expect(screenLines.length).toBe 3 + [line1, line2, line3] = screenLines + expect(line1).toEqual [{value: "01234 ", type: 1}] + expect(line2).toEqual [{value: "67891234 ", type: 1}] + expect(line3).toEqual [{value: "6789", type: 1}] + describe "when the exceeding token is only whitespace", -> it "keeps the token on the first line and places the following token on the next line", -> screenLines = wrapper.splitTokens([{value: '12345'}, {value: '123'}, {value: ' '}, {value: 'ghi'}]) diff --git a/src/atom/line-wrapper.coffee b/src/atom/line-wrapper.coffee index 320e30b75..095671d0f 100644 --- a/src/atom/line-wrapper.coffee +++ b/src/atom/line-wrapper.coffee @@ -59,7 +59,8 @@ class LineWrapper # if no whitespace, split it all to next line if it will fit. # if it's longer than the max width, chop it without regard for whitespace. - unless /\s/.test(value) + hasNoWhitespace = not /\s/.test(value) + if hasNoWhitespace if value.length > @maxLength return @splitTokenAt(token, boundaryIndex) else @@ -72,8 +73,8 @@ class LineWrapper wordStart = /\b\w/g while match = wordStart.exec(value) + break if match.index > boundaryIndex splitIndex = match.index - break if splitIndex > boundaryIndex # if the only word start is at the beginning of the token, put the whole token on the next line return [null, token] if splitIndex == 0