Ctrl-k cuts to the end of the line

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-09 12:34:30 -06:00
parent 54396a7646
commit f3372f08de
5 changed files with 44 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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