diff --git a/spec/text-editor-spec.js b/spec/text-editor-spec.js index ef2ced5e6..328b7e8c4 100644 --- a/spec/text-editor-spec.js +++ b/spec/text-editor-spec.js @@ -5401,6 +5401,34 @@ describe('TextEditor', () => { expect(buffer.getLineCount()).toBe(count - 2) }) + it("restores cursor position for multiple cursors", () => { + const line = '0123456789'.repeat(8) + editor.setText((line + '\n').repeat(5)) + editor.setCursorScreenPosition([0, 5]) + editor.addCursorAtScreenPosition([2, 8]) + editor.deleteLine() + + const cursors = editor.getCursors() + expect(cursors.length).toBe(2) + expect(cursors[0].getScreenPosition()).toEqual([0, 5]) + expect(cursors[1].getScreenPosition()).toEqual([1, 8]) + }) + + it("restores cursor position for multiple selections", () => { + const line = '0123456789'.repeat(8) + editor.setText((line + '\n').repeat(5)) + editor.setSelectedBufferRanges([ + [[0, 5], [0, 8]], + [[2, 4], [2, 15]] + ]) + editor.deleteLine() + + const cursors = editor.getCursors() + expect(cursors.length).toBe(2) + expect(cursors[0].getScreenPosition()).toEqual([0, 5]) + expect(cursors[1].getScreenPosition()).toEqual([1, 4]) + }) + it('deletes a line only once when multiple selections are on the same line', () => { const line1 = buffer.lineForRow(1) const count = buffer.getLineCount() diff --git a/src/selection.js b/src/selection.js index 99c1ea95e..a15f6dcbd 100644 --- a/src/selection.js +++ b/src/selection.js @@ -585,7 +585,8 @@ class Selection { // is empty unless the selection spans multiple lines in which case all lines // are removed. deleteLine () { - if (this.isEmpty()) { + const range = this.getBufferRange() + if (range.isEmpty()) { const start = this.cursor.getScreenRow() const range = this.editor.bufferRowsForScreenRows(start, start + 1) if (range[1] > range[0]) { @@ -594,12 +595,12 @@ class Selection { this.editor.buffer.deleteRow(range[0]) } } else { - const range = this.getBufferRange() const start = range.start.row let end = range.end.row if (end !== this.editor.buffer.getLastRow() && range.end.column === 0) end-- this.editor.buffer.deleteRows(start, end) } + this.cursor.setBufferPosition({row: this.cursor.getBufferRow(), column: range.start.column}) } // Public: Joins the current line with the one below it. Lines will