diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index cd1cc92cb..a7ef2528a 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -75,7 +75,7 @@ describe "DisplayBuffer", -> expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe ' return ' atom.config.set('editor.preferredLineLength', 5) - expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe 'funct' + expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe ' fun' atom.config.set('editor.softWrapAtPreferredLineLength', false) expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe ' return ' @@ -92,7 +92,7 @@ describe "DisplayBuffer", -> describe "when there is whitespace before the boundary", -> it "wraps the line at the end of the first whitespace preceding the boundary", -> expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe ' return ' - expect(displayBuffer.tokenizedLineForScreenRow(11).text).toBe 'sort(left).concat(pivot).concat(sort(right));' + expect(displayBuffer.tokenizedLineForScreenRow(11).text).toBe ' sort(left).concat(pivot).concat(sort(right));' describe "when there is no whitespace before the boundary", -> it "wraps the line exactly at the boundary since there's no more graceful place to wrap it", -> @@ -105,7 +105,7 @@ describe "DisplayBuffer", -> describe "when there is a whitespace character at the max length boundary", -> it "wraps the line at the first non-whitespace character following the boundary", -> expect(displayBuffer.tokenizedLineForScreenRow(3).text).toBe ' var pivot = items.shift(), current, left = [], ' - expect(displayBuffer.tokenizedLineForScreenRow(4).text).toBe 'right = [];' + expect(displayBuffer.tokenizedLineForScreenRow(4).text).toBe ' right = [];' describe "when there are hard tabs", -> beforeEach -> @@ -138,8 +138,8 @@ describe "DisplayBuffer", -> it "rewraps the line and emits a change event", -> buffer.insert([6, 28], '1234567890') expect(displayBuffer.tokenizedLineForScreenRow(7).text).toBe ' current < pivot ? ' - expect(displayBuffer.tokenizedLineForScreenRow(8).text).toBe 'left1234567890.push(current) : ' - expect(displayBuffer.tokenizedLineForScreenRow(9).text).toBe 'right.push(current);' + expect(displayBuffer.tokenizedLineForScreenRow(8).text).toBe ' left1234567890.push(current) : ' + expect(displayBuffer.tokenizedLineForScreenRow(9).text).toBe ' right.push(current);' expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe ' }' expect(changeHandler).toHaveBeenCalledWith(start: 7, end: 8, screenDelta: 1, bufferDelta: 0) @@ -148,7 +148,7 @@ describe "DisplayBuffer", -> it "inserts / updates wrapped lines and emits a change event", -> buffer.insert([6, 21], '1234567890 abcdefghij 1234567890\nabcdefghij') expect(displayBuffer.tokenizedLineForScreenRow(7).text).toBe ' current < pivot1234567890 abcdefghij ' - expect(displayBuffer.tokenizedLineForScreenRow(8).text).toBe '1234567890' + expect(displayBuffer.tokenizedLineForScreenRow(8).text).toBe ' 1234567890' expect(displayBuffer.tokenizedLineForScreenRow(9).text).toBe 'abcdefghij ? left.push(current) : ' expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe 'right.push(current);' @@ -159,7 +159,7 @@ describe "DisplayBuffer", -> buffer.setTextInRange([[3, 21], [7, 5]], ';') expect(displayBuffer.tokenizedLineForScreenRow(3).text).toBe ' var pivot = items;' expect(displayBuffer.tokenizedLineForScreenRow(4).text).toBe ' return ' - expect(displayBuffer.tokenizedLineForScreenRow(5).text).toBe 'sort(left).concat(pivot).concat(sort(right));' + expect(displayBuffer.tokenizedLineForScreenRow(5).text).toBe ' sort(left).concat(pivot).concat(sort(right));' expect(displayBuffer.tokenizedLineForScreenRow(6).text).toBe ' };' expect(changeHandler).toHaveBeenCalledWith(start: 3, end: 9, screenDelta: -6, bufferDelta: -4) @@ -193,8 +193,8 @@ describe "DisplayBuffer", -> expect(displayBuffer.screenPositionForBufferPosition([3, 51])).toEqual([3, 50]) expect(displayBuffer.bufferPositionForScreenPosition([4, 0])).toEqual([3, 51]) expect(displayBuffer.bufferPositionForScreenPosition([3, 50])).toEqual([3, 50]) - expect(displayBuffer.screenPositionForBufferPosition([3, 62])).toEqual([4, 11]) - expect(displayBuffer.bufferPositionForScreenPosition([4, 11])).toEqual([3, 62]) + expect(displayBuffer.screenPositionForBufferPosition([3, 62])).toEqual([4, 15]) + expect(displayBuffer.bufferPositionForScreenPosition([4, 11])).toEqual([3, 58]) # following a wrapped line expect(displayBuffer.screenPositionForBufferPosition([4, 5])).toEqual([5, 5]) @@ -209,9 +209,9 @@ describe "DisplayBuffer", -> describe ".setEditorWidthInChars(length)", -> it "changes the length at which lines are wrapped and emits a change event for all screen lines", -> displayBuffer.setEditorWidthInChars(40) - expect(tokensText displayBuffer.tokenizedLineForScreenRow(4).tokens).toBe 'left = [], right = [];' + expect(tokensText displayBuffer.tokenizedLineForScreenRow(4).tokens).toBe ' left = [], right = [];' expect(tokensText displayBuffer.tokenizedLineForScreenRow(5).tokens).toBe ' while(items.length > 0) {' - expect(tokensText displayBuffer.tokenizedLineForScreenRow(12).tokens).toBe 'sort(left).concat(pivot).concat(sort(rig' + expect(tokensText displayBuffer.tokenizedLineForScreenRow(12).tokens).toBe ' sort(left).concat(pivot).concat(sort' expect(changeHandler).toHaveBeenCalledWith(start: 0, end: 15, screenDelta: 3, bufferDelta: 0) it "only allows positive widths to be assigned", -> @@ -594,11 +594,23 @@ describe "DisplayBuffer", -> expect(displayBuffer.clipScreenPosition([1000, 0])).toEqual [15, 2] expect(displayBuffer.clipScreenPosition([1000, 1000])).toEqual [15, 2] + describe "when wrapAtPhantomTokens is false (the default)", -> + it "clips positions inside a phantom token to the beginning of the line", -> + expect(displayBuffer.clipScreenPosition([4, 0])).toEqual [4, 4] + expect(displayBuffer.clipScreenPosition([4, 1])).toEqual [4, 4] + expect(displayBuffer.clipScreenPosition([4, 3])).toEqual [4, 4] + + describe "when wrapAtPhantomTokens is true", -> + it "wraps positions inside a phantom token to the previous line", -> + expect(displayBuffer.clipScreenPosition([4, 0], wrapAtPhantomTokens: true)).toEqual [3, 51] + expect(displayBuffer.clipScreenPosition([4, 1], wrapAtPhantomTokens: true)).toEqual [3, 51] + expect(displayBuffer.clipScreenPosition([4, 3], wrapAtPhantomTokens: true)).toEqual [3, 51] + describe "when wrapBeyondNewlines is false (the default)", -> it "wraps positions beyond the end of hard newlines to the end of the line", -> expect(displayBuffer.clipScreenPosition([1, 10000])).toEqual [1, 30] - expect(displayBuffer.clipScreenPosition([4, 30])).toEqual [4, 11] - expect(displayBuffer.clipScreenPosition([4, 1000])).toEqual [4, 11] + expect(displayBuffer.clipScreenPosition([4, 30])).toEqual [4, 15] + expect(displayBuffer.clipScreenPosition([4, 1000])).toEqual [4, 15] describe "when wrapBeyondNewlines is true", -> it "wraps positions past the end of hard newlines to the next line", -> @@ -620,9 +632,9 @@ describe "DisplayBuffer", -> describe "when wrapAtSoftNewlines is true", -> it "wraps positions at the end of soft-wrapped lines to the next screen line", -> expect(displayBuffer.clipScreenPosition([3, 50], wrapAtSoftNewlines: true)).toEqual [3, 50] - expect(displayBuffer.clipScreenPosition([3, 51], wrapAtSoftNewlines: true)).toEqual [4, 0] - expect(displayBuffer.clipScreenPosition([3, 58], wrapAtSoftNewlines: true)).toEqual [4, 0] - expect(displayBuffer.clipScreenPosition([3, 1000], wrapAtSoftNewlines: true)).toEqual [4, 0] + expect(displayBuffer.clipScreenPosition([3, 51], wrapAtSoftNewlines: true)).toEqual [4, 4] + expect(displayBuffer.clipScreenPosition([3, 58], wrapAtSoftNewlines: true)).toEqual [4, 4] + expect(displayBuffer.clipScreenPosition([3, 1000], wrapAtSoftNewlines: true)).toEqual [4, 4] describe "when skipAtomicTokens is false (the default)", -> it "clips screen positions in the middle of atomic tab characters to the beginning of the character", -> @@ -655,7 +667,7 @@ describe "DisplayBuffer", -> buffer.setText('\t\taa bb cc dd ee ff gg') displayBuffer.setSoftWrapped(true) displayBuffer.setEditorWidthInChars(10) - expect(displayBuffer.screenPositionForBufferPosition([0, 10], wrapAtSoftNewlines: true)).toEqual [1, 0] + expect(displayBuffer.screenPositionForBufferPosition([0, 10], wrapAtSoftNewlines: true)).toEqual [1, 4] expect(displayBuffer.bufferPositionForScreenPosition([1, 0])).toEqual [0, 10] describe "::getMaxLineLength()", -> diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index fe12d6532..f45f3063f 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -432,6 +432,16 @@ describe "TextEditor", -> editor.moveLeft() expect(editor.getCursorScreenPosition()).toEqual [10, 0] + describe "when line is wrapped and follow previous line indentation", -> + beforeEach -> + editor.setSoftWrapped(true) + editor.setEditorWidthInChars(50) + + it "wraps to the end of the previous line", -> + editor.setCursorScreenPosition([4, 4]) + editor.moveLeft() + expect(editor.getCursorScreenPosition()).toEqual [3, 50] + describe "when the cursor is on the first line", -> it "remains in the same position (0,0)", -> editor.setCursorScreenPosition(row: 0, column: 0) @@ -628,11 +638,11 @@ describe "TextEditor", -> editor.moveToFirstCharacterOfLine() [cursor1, cursor2] = editor.getCursors() expect(cursor1.getScreenPosition()).toEqual [2,0] - expect(cursor2.getScreenPosition()).toEqual [8,4] + expect(cursor2.getScreenPosition()).toEqual [8,2] editor.moveToFirstCharacterOfLine() expect(cursor1.getScreenPosition()).toEqual [2,0] - expect(cursor2.getScreenPosition()).toEqual [8,0] + expect(cursor2.getScreenPosition()).toEqual [8,2] describe "when soft wrap is off", -> it "moves to the first character of the current line or the beginning of the line if it's already on the first character", -> diff --git a/spec/tokenized-buffer-spec.coffee b/spec/tokenized-buffer-spec.coffee index 41a63a562..103a54b85 100644 --- a/spec/tokenized-buffer-spec.coffee +++ b/spec/tokenized-buffer-spec.coffee @@ -670,8 +670,8 @@ describe "TokenizedBuffer", -> [segment1, segment2] = tokenizedLine.softWrapAt(16) expect(segment1.tokens[5].value).toBe ' ' expect(segment1.tokens[5].firstTrailingWhitespaceIndex).toBe null - expect(segment2.tokens[6].value).toBe ' ' - expect(segment2.tokens[6].firstTrailingWhitespaceIndex).toBe 0 + expect(segment2.tokens[7].value).toBe ' ' + expect(segment2.tokens[7].firstTrailingWhitespaceIndex).toBe 0 it "sets leading and trailing whitespace correctly on a line with invisible characters that is copied", -> buffer.setText(" \t a line with tabs\tand \tspaces \t ")