diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index c6790acfb..522e4372e 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1644,6 +1644,35 @@ describe "Editor", -> editor.trigger 'delete-to-end-of-word' expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {' + describe "cut-to-end-of-line", -> + pasteboard = null + + beforeEach -> + spyOn($native, 'writeToPasteboard').andCallFake (text) -> pasteboard = text + spyOn($native, 'readFromPasteboard').andCallFake -> pasteboard + + describe "when nothing is selected", -> + it "cuts up to the end of the line", -> + editor.setCursorBufferPosition([2, 20]) + editor.addCursorAtBufferPosition([3, 20]) + editor.trigger 'cut-to-end-of-line' + + expect(buffer.lineForRow(2)).toBe ' if (items.length' + expect(buffer.lineForRow(3)).toBe ' var pivot = item' + + expect(pasteboard).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' + + describe "when text is selected", -> + it "only cuts the selected text, not to the end of the line", -> + editor.setSelectedBufferRanges([[[2,20], [2, 30]], [[3, 20], [3, 20]]]) + + editor.trigger 'cut-to-end-of-line' + + expect(buffer.lineForRow(2)).toBe ' if (items.lengthurn items;' + expect(buffer.lineForRow(3)).toBe ' var pivot = item' + + expect(pasteboard).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' + describe "tab", -> describe "if editor.softTabs is true (the default)", -> it "inserts editor.tabText into the buffer", -> diff --git a/src/app/composite-selection.coffee b/src/app/composite-selection.coffee index 7959c01eb..b7125aea8 100644 --- a/src/app/composite-selection.coffee +++ b/src/app/composite-selection.coffee @@ -136,9 +136,15 @@ class CompositeSeleciton selectToEndOfWord: -> @expandSelectionsForward (selection) => selection.selectToEndOfWord() + cutToEndOfLine: -> + maintainPasteboard = false + @mutateSelectedText (selection) -> + selection.cutToEndOfLine(maintainPasteboard) + maintainPasteboard = true + cut: -> maintainPasteboard = false - for selection in @getSelections() + @mutateSelectedText (selection) -> selection.cut(maintainPasteboard) maintainPasteboard = true diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 98b6bc17d..74b5f9640 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -65,11 +65,12 @@ class Editor extends View @on 'select-up', => @selectUp() @on 'select-down', => @selectDown() @on 'newline', => @insertText("\n") + @on 'tab', => @insertTab() @on 'backspace', => @backspace() @on 'backspace-to-beginning-of-word', => @backspaceToBeginningOfWord() @on 'delete', => @delete() @on 'delete-to-end-of-word', => @deleteToEndOfWord() - @on 'tab', => @insertTab() + @on 'cut-to-end-of-line', => @cutToEndOfLine() @on 'cut', => @cutSelection() @on 'copy', => @copySelection() @on 'paste', => @paste() @@ -401,6 +402,7 @@ class Editor extends View backspaceToBeginningOfWord: -> @compositeSelection.backspaceToBeginningOfWord() delete: -> @compositeSelection.delete() deleteToEndOfWord: -> @compositeSelection.deleteToEndOfWord() + cutToEndOfLine: -> @compositeSelection.cutToEndOfLine() setText: (text) -> @buffer.setText(text) getText: -> @buffer.getText() diff --git a/src/app/keymaps/emacs.coffee b/src/app/keymaps/emacs.coffee index 9cc5c3afd..84a8a2967 100644 --- a/src/app/keymaps/emacs.coffee +++ b/src/app/keymaps/emacs.coffee @@ -11,3 +11,4 @@ window.keymap.bindKeys '.editor', 'ctrl-d': 'delete' 'alt-h': 'backspace-to-beginning-of-word' 'alt-d': 'delete-to-end-of-word' + 'ctrl-k': 'cut-to-end-of-line' diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 2a71c12d0..74678ed2c 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -204,6 +204,10 @@ class Selection extends View selectToEndOfWord: -> @modifySelection => @cursor.moveToEndOfWord() + cutToEndOfLine: (maintainPasteboard) -> + @selectToEndOfLine() if @isEmpty() + @cut(maintainPasteboard) + cut: (maintainPasteboard=false) -> @copy(maintainPasteboard) @delete()