deleting only selection if selection is not empty

This commit is contained in:
Allen Nelson
2014-06-16 16:13:40 -05:00
parent fc462fcd21
commit 8411d41621
3 changed files with 13 additions and 13 deletions

View File

@@ -1851,11 +1851,11 @@ describe "Editor", ->
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', ->
it 'deletes only the text in the 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 ''
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
expect(buffer.lineForRow(2)).toBe 'if (items.length <= 1) return items;'
describe ".deleteToBeginningOfLine()", ->
describe "when no text is selected", ->

View File

@@ -691,8 +691,9 @@ class Editor extends Model
@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.
# of the containing line following the cursor, or if the cursor is at the end
# of the line, delete the following newline. If not empty, delete the
# selected text.
deleteToEndOfLine: ->
@mutateSelectedText (selection) -> selection.deleteToEndOfLine()

View File

@@ -430,15 +430,14 @@ 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.
# Public: If nothing selected, removes all characters from cursor
# until the end of the current line, unless already at the end of
# the line, in which case removes the following newline.
# If there is a selection, deletes only the selection.
deleteToEndOfLine: ->
if @isEmpty() and @cursor.isAtEndOfLine()
@delete()
else
@selectToEndOfLine()
@deleteSelectedText()
return @delete() if @isEmpty() and @cursor.isAtEndOfLine()
@selectToEndOfLine() if @isEmpty()
@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.