diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 485ebe0ef..74c4a0d54 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1831,6 +1831,32 @@ describe "Editor", -> expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {' expect(buffer.lineForRow(2)).toBe 'if (items.length <= 1) return items;' + describe '.deleteToEndOfLine()', -> + describe 'when no text is selected', -> + it 'deletes all text between the cursor and the end of the line', -> + editor.setCursorBufferPosition([1, 24]) + editor.addCursorAtBufferPosition([2, 5]) + [cursor1, cursor2] = editor.getCursors() + + editor.deleteToEndOfLine() + expect(buffer.lineForRow(1)).toBe ' var sort = function(it' + expect(buffer.lineForRow(2)).toBe ' i' + expect(cursor1.getBufferPosition()).toEqual [1, 24] + expect(cursor2.getBufferPosition()).toEqual [2, 5] + + describe 'when at the end of the line', -> + it 'deletes the next newline', -> + editor.setCursorBufferPosition([1, 30]) + editor.deleteToEndOfLine() + expect(buffer.lineForRow(1)).toBe ' var sort = function(items) { if (items.length <= 1) return items;' + + describe 'when text is selected', -> + it 'deletes all text to end of the line starting from selection', -> + editor.setSelectedBufferRanges([[[1, 24], [1, 27]], [[2, 0], [2, 4]]]) + editor.deleteToEndOfLine() + expect(buffer.lineForRow(1)).toBe ' var sort = function(it' + expect(buffer.lineForRow(2)).toBe '' + describe ".deleteToBeginningOfLine()", -> describe "when no text is selected", -> it "deletes all text between the cursor and the beginning of the line", -> diff --git a/src/editor-component.coffee b/src/editor-component.coffee index edca56a65..565c8c655 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -291,6 +291,7 @@ EditorComponent = React.createClass 'editor:consolidate-selections': @consolidateSelections 'editor:delete-to-beginning-of-word': => editor.deleteToBeginningOfWord() 'editor:delete-to-beginning-of-line': => editor.deleteToBeginningOfLine() + 'editor:delete-to-end-of-line': => editor.deleteToEndOfLine() 'editor:delete-to-end-of-word': => editor.deleteToEndOfWord() 'editor:delete-line': => editor.deleteLine() 'editor:cut-to-end-of-line': => editor.cutToEndOfLine() diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 53b05ab56..7c8955328 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -157,6 +157,7 @@ class EditorView extends View 'editor:consolidate-selections': (event) => @consolidateSelections(event) 'editor:delete-to-beginning-of-word': => @editor.deleteToBeginningOfWord() 'editor:delete-to-beginning-of-line': => @editor.deleteToBeginningOfLine() + 'editor:delete-to-end-of-line': => @editor.deleteToEndOfLine() 'editor:delete-to-end-of-word': => @editor.deleteToEndOfWord() 'editor:delete-line': => @editor.deleteLine() 'editor:cut-to-end-of-line': => @editor.cutToEndOfLine() diff --git a/src/editor.coffee b/src/editor.coffee index d500365fa..9d04ff720 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -112,6 +112,7 @@ TextMateScopeSelector = require('first-mate').ScopeSelector # - {::deleteToBeginningOfWord} # - {::deleteToBeginningOfLine} # - {::delete} +# - {::deleteToEndOfLine} # - {::deleteToEndOfWord} # - {::deleteLine} # - {::cutSelectedText} @@ -689,6 +690,12 @@ class Editor extends Model delete: -> @mutateSelectedText (selection) -> selection.delete() + # Public: For each selection, if the selection is empty, delete all characters + # of the containing line following the cursor. Otherwise delete the selected + # text. + deleteToEndOfLine: -> + @mutateSelectedText (selection) -> selection.deleteToEndOfLine() + # Public: For each selection, if the selection is empty, delete all characters # of the containing word following the cursor. Otherwise delete the selected # text. diff --git a/src/selection.coffee b/src/selection.coffee index c04fc7231..472d4e888 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -430,6 +430,16 @@ class Selection extends Model @selectRight() @deleteSelectedText() + # Public: Removes all characters from the end of the selection to the end of + # the current line (if no selection then the rest of the line). + # If the cursor is at the end of the line, deletes the newline. + deleteToEndOfLine: -> + if @isEmpty() and @cursor.isAtEndOfLine() + @delete() + else + @selectToEndOfLine() + @deleteSelectedText() + # Public: Removes the selection or all characters from the start of the # selection to the end of the current word if nothing is selected. deleteToEndOfWord: ->