added delete to end of line

This commit is contained in:
Allen Nelson
2014-06-15 00:38:11 -05:00
parent 5f602ad86e
commit fc462fcd21
5 changed files with 45 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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