From 09ffa8bec9cb2f547a18596d44f37e52e6578c73 Mon Sep 17 00:00:00 2001 From: abe33 Date: Sun, 11 Oct 2015 18:15:06 +0200 Subject: [PATCH] :bug: Fix moving multiple selections down locked at wrapped line --- spec/text-editor-spec.coffee | 21 +++++++++++++++++++++ src/text-editor.coffee | 13 ++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 71283d324..2b6514e12 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -2075,6 +2075,27 @@ describe "TextEditor", -> expect(editor.getSelectedBufferRanges()).toEqual [[[4, 12], [4, 13]], [[4, 2], [4, 9]]] expect(editor.lineTextForBufferRow(3)).toBe " while(items.length > 0) {" + describe "when the selections are above a wrapped line", -> + beforeEach -> + editor.setSoftWrapped(true) + editor.setEditorWidthInChars(80) + editor.setText(""" + 1 + 2 + Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. + 3 + 4 + """) + + it 'moves the lines past the soft wrapped line', -> + editor.setSelectedBufferRanges([[[0, 0], [0, 0]], [[1, 0], [1, 0]]]) + + editor.moveLineDown() + + expect(editor.lineTextForBufferRow(0)).not.toBe "2" + expect(editor.lineTextForBufferRow(1)).toBe "1" + expect(editor.lineTextForBufferRow(2)).toBe "2" + describe ".insertText(text)", -> describe "when there is a single selection", -> beforeEach -> diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 952b677f6..83f9dc240 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -885,9 +885,16 @@ class TextEditor extends Model linesRange = new Range(linesRangeStart, [selection.end.row + 1, 0]) # If selected line range is followed by a fold, one line below on screen - # could be multiple lines in the buffer. - followingScreenRow = @screenRowForBufferRow(linesRange.end.row) + 1 - followingBufferRow = @bufferRowForScreenRow(followingScreenRow) + # could be multiple lines in the buffer. But at the same time, if the + # next buffer row is wrapped, one line in the buffer can represent many + # screen rows. + [nextBufferRowScreenStart, nextBufferRowScreenEnd] = @displayBuffer.rowMap.screenRowRangeForBufferRow(linesRange.end.row) + if nextBufferRowScreenEnd - nextBufferRowScreenStart > 1 + followingScreenRow = nextBufferRowScreenEnd + followingBufferRow = @bufferRowForScreenRow(followingScreenRow) + else + followingScreenRow = @screenRowForBufferRow(linesRange.end.row) + 1 + followingBufferRow = @bufferRowForScreenRow(followingScreenRow) insertDelta = followingBufferRow - linesRange.end.row # Any folds in the text that is moved will need to be re-created.