Merge pull request #12783 from vedharish/editor_delete_line

This commit is contained in:
Max Brunsfeld
2018-01-08 15:58:22 -08:00
2 changed files with 31 additions and 2 deletions

View File

@@ -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()

View File

@@ -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