mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Token with interstitial whitespace is split before LineWrapper.maxLength
This commit is contained in:
@@ -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'}])
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user