From 8411d416213822ddcd3b4a0079580488e0da815f Mon Sep 17 00:00:00 2001 From: Allen Nelson Date: Mon, 16 Jun 2014 16:13:40 -0500 Subject: [PATCH] deleting only selection if selection is not empty --- spec/editor-spec.coffee | 6 +++--- src/editor.coffee | 5 +++-- src/selection.coffee | 15 +++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 74c4a0d54..af20378f9 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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", -> diff --git a/src/editor.coffee b/src/editor.coffee index 9d04ff720..e93752b43 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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() diff --git a/src/selection.coffee b/src/selection.coffee index 472d4e888..a9d93925f 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -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.