diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index f4c343e1f..664c8fdd0 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -862,7 +862,6 @@ describe "Editor", -> expect(editor.lineForBufferRow(1)).toBe " = functi" expect(editor.lineForBufferRow(2)).toBe " () {" - describe "backspace", -> describe "when cursors are on the same line", -> it "removes the characters preceding each cursor", -> @@ -914,6 +913,64 @@ describe "Editor", -> expect(cursor1.getBufferPosition()).toEqual [2,40] expect(cursor2.getBufferPosition()).toEqual [4,30] + describe "when selections are on the same line", -> + it "removes all selected text", -> + editor.setSelectionBufferRange([[0,4], [0,13]]) + editor.addSelectionForBufferRange([[0,22], [0,24]]) + + editor.backspace() + + expect(editor.lineForBufferRow(0)).toBe 'var = functio () {' + + describe "delete", -> + describe "when cursors are on the same line", -> + it "removes the characters following each cursor", -> + editor.setCursorScreenPosition([3, 13]) + editor.addCursorAtScreenPosition([3, 38]) + + editor.delete() + + expect(editor.lineForBufferRow(3)).toBe " var pivot= items.shift(), current left = [], right = [];" + + [cursor1, cursor2] = editor.compositeCursor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [3, 13] + expect(cursor2.getBufferPosition()).toEqual [3, 37] + + [selection1, selection2] = editor.compositeSelection.getSelections() + expect(selection1.isEmpty()).toBeTruthy() + expect(selection2.isEmpty()).toBeTruthy() + + describe "when cursors are on different lines", -> + it "removes the characters following each cursor", -> + editor.setCursorScreenPosition([3, 13]) + editor.addCursorAtScreenPosition([4, 10]) + + editor.delete() + + expect(editor.lineForBufferRow(3)).toBe " var pivot= items.shift(), current, left = [], right = [];" + expect(editor.lineForBufferRow(4)).toBe " while(tems.length > 0) {" + + [cursor1, cursor2] = editor.compositeCursor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [3, 13] + expect(cursor2.getBufferPosition()).toEqual [4, 10] + + [selection1, selection2] = editor.compositeSelection.getSelections() + expect(selection1.isEmpty()).toBeTruthy() + expect(selection2.isEmpty()).toBeTruthy() + + describe "when deleting over newlines", -> + it "removes the newlines following each cursor", -> + editor.setCursorScreenPosition([0, 29]) + editor.addCursorAtScreenPosition([1, 30]) + + editor.delete() + + expect(editor.lineForBufferRow(0)).toBe "var quicksort = function () { var sort = function(items) { if (items.length <= 1) return items;" + + [cursor1, cursor2] = editor.compositeCursor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [0,29] + expect(cursor2.getBufferPosition()).toEqual [0,59] + describe "keyboard movement", -> it "moves all cursors", -> editor.setCursorScreenPosition([3, 13]) diff --git a/spec/atom/selection-spec.coffee b/spec/atom/selection-spec.coffee index 1376ac9b4..76bb9625e 100644 --- a/spec/atom/selection-spec.coffee +++ b/spec/atom/selection-spec.coffee @@ -20,28 +20,28 @@ describe "Selection", -> expect(selection.anchorScreenPosition).toEqual range.start expect(selection.cursor.getScreenPosition()).toEqual range.end - describe ".delete()", -> + describe ".deleteSelectedText()", -> describe "when nothing is selected", -> it "deletes nothing", -> selection.setBufferRange new Range([0,3], [0,3]) - selection.delete() + selection.deleteSelectedText() expect(editor.buffer.lineForRow(0)).toBe "var quicksort = function () {" describe "when one line is selected", -> it "deletes selected text", -> selection.setBufferRange new Range([0,4], [0,14]) - selection.delete() + selection.deleteSelectedText() expect(editor.buffer.lineForRow(0)).toBe "var = function () {" endOfLine = editor.buffer.lineForRow(0).length selection.setBufferRange new Range([0,0], [0, endOfLine]) - selection.delete() + selection.deleteSelectedText() expect(editor.buffer.lineForRow(0)).toBe "" describe "when multiple lines are selected", -> it "deletes selected text", -> selection.setBufferRange new Range([0,1], [2,39]) - selection.delete() + selection.deleteSelectedText() expect(editor.buffer.lineForRow(0)).toBe "v;" describe ".updateAppearence()", -> diff --git a/src/atom/composite-selection.coffee b/src/atom/composite-selection.coffee index 368602266..8f44d33f5 100644 --- a/src/atom/composite-selection.coffee +++ b/src/atom/composite-selection.coffee @@ -38,6 +38,10 @@ class CompositeSeleciton for selection in @getSelections() selection.backspace() + delete: -> + for selection in @getSelections() + selection.delete() + selectToScreenPosition: (position) -> @lastSelection().selectToScreenPosition(position) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 6967b53ff..914481b2c 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -386,8 +386,7 @@ class Editor extends View @compositeSelection.backspace() delete: -> - @selectRight() if @getSelection().isEmpty() - @getSelection().delete() + @compositeSelection.delete() undo: -> @buffer.undo() @@ -442,4 +441,4 @@ class Editor extends View @renderer.lineForRow(row).state getCurrentMode: -> - @buffer.getMode() \ No newline at end of file + @buffer.getMode() diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 5adcc33b7..6b84eba82 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -121,10 +121,14 @@ class Selection extends View backspace: -> @selectLeft() if @isEmpty() - @delete() + @deleteSelectedText() @clearSelection() delete: -> + @selectRight() if @isEmpty() + @deleteSelectedText() + + deleteSelectedText: -> range = @getBufferRange() @editor.buffer.delete(range) unless range.isEmpty()