Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions spec/text-editor-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1430,12 +1430,12 @@ describe "TextEditor", ->
expect(selection2.getBufferRange()).toEqual [[11, 0], [11, 3]]
expect(selection2.isReversed()).toBeTruthy()

describe ".selectToEndOfLine()", ->
it "selects text from cusor position to end of line", ->
describe ".selectToEndOfScreenLine()", ->
it "selects text from cusor position to end of screen line", ->
editor.setCursorScreenPosition [12, 0]
editor.addCursorAtScreenPosition [11, 3]

editor.selectToEndOfLine()
editor.selectToEndOfScreenLine()

expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
Expand Down Expand Up @@ -3444,14 +3444,14 @@ describe "TextEditor", ->
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
expect(buffer.lineForRow(2)).toBe 'if (items.length <= 1) return items;'

describe '.deleteToEndOfLine()', ->
describe '.deleteToEndOfScreenLine()', ->
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()
editor.deleteToEndOfScreenLine()
expect(buffer.lineForRow(1)).toBe ' var sort = function(it'
expect(buffer.lineForRow(2)).toBe ' i'
expect(cursor1.getBufferPosition()).toEqual [1, 24]
Expand All @@ -3460,13 +3460,13 @@ describe "TextEditor", ->
describe 'when at the end of the line', ->
it 'deletes the next newline', ->
editor.setCursorBufferPosition([1, 30])
editor.deleteToEndOfLine()
editor.deleteToEndOfScreenLine()
expect(buffer.lineForRow(1)).toBe ' var sort = function(items) { if (items.length <= 1) return items;'

describe 'when text is selected', ->
it 'deletes only the text in the selection', ->
editor.setSelectedBufferRanges([[[1, 24], [1, 27]], [[2, 0], [2, 4]]])
editor.deleteToEndOfLine()
editor.deleteToEndOfScreenLine()
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
expect(buffer.lineForRow(2)).toBe 'if (items.length <= 1) return items;'

Expand Down Expand Up @@ -3802,22 +3802,22 @@ describe "TextEditor", ->
items
"""

describe ".cutToEndOfLine()", ->
describe ".cutToEndOfScreenLine()", ->
describe "when soft wrap is on", ->
it "cuts up to the end of the line", ->
editor.setSoftWrapped(true)
editor.setDefaultCharWidth(1)
editor.setEditorWidthInChars(10)
editor.setCursorScreenPosition([2, 2])
editor.cutToEndOfLine()
editor.cutToEndOfScreenLine()
expect(editor.tokenizedLineForScreenRow(2).text).toBe '= () {'

describe "when soft wrap is off", ->
describe "when nothing is selected", ->
it "cuts up to the end of the line", ->
editor.setCursorBufferPosition([2, 20])
editor.addCursorAtBufferPosition([3, 20])
editor.cutToEndOfLine()
editor.cutToEndOfScreenLine()
expect(buffer.lineForRow(2)).toBe ' if (items.length'
expect(buffer.lineForRow(3)).toBe ' var pivot = item'
expect(atom.clipboard.read()).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];'
Expand All @@ -3826,7 +3826,7 @@ describe "TextEditor", ->
it "only cuts the selected text, not to the end of the line", ->
editor.setSelectedBufferRanges([[[2, 20], [2, 30]], [[3, 20], [3, 20]]])

editor.cutToEndOfLine()
editor.cutToEndOfScreenLine()

expect(buffer.lineForRow(2)).toBe ' if (items.lengthurn items;'
expect(buffer.lineForRow(3)).toBe ' var pivot = item'
Expand Down
7 changes: 4 additions & 3 deletions src/register-default-commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ module.exports = ({commandRegistry, commandInstaller, config}) ->
'editor:move-to-next-subword-boundary': -> @moveToNextSubwordBoundary()
'editor:select-to-beginning-of-next-paragraph': -> @selectToBeginningOfNextParagraph()
'editor:select-to-beginning-of-previous-paragraph': -> @selectToBeginningOfPreviousParagraph()
'editor:select-to-end-of-line': -> @selectToEndOfLine()
'editor:select-to-end-of-buffer-line': -> @selectToEndOfBufferLine()
'editor:select-to-end-of-screen-line': -> @selectToEndOfScreenLine()
'editor:select-to-beginning-of-line': -> @selectToBeginningOfLine()
'editor:select-to-end-of-word': -> @selectToEndOfWord()
'editor:select-to-beginning-of-word': -> @selectToBeginningOfWord()
Expand All @@ -144,12 +145,12 @@ module.exports = ({commandRegistry, commandInstaller, config}) ->
'editor:delete-to-next-word-boundary': -> @deleteToNextWordBoundary()
'editor:delete-to-beginning-of-word': -> @deleteToBeginningOfWord()
'editor:delete-to-beginning-of-line': -> @deleteToBeginningOfLine()
'editor:delete-to-end-of-line': -> @deleteToEndOfLine()
'editor:delete-to-end-of-screen-line': -> @deleteToEndOfScreenLine()
'editor:delete-to-end-of-word': -> @deleteToEndOfWord()
'editor:delete-to-beginning-of-subword': -> @deleteToBeginningOfSubword()
'editor:delete-to-end-of-subword': -> @deleteToEndOfSubword()
'editor:delete-line': -> @deleteLine()
'editor:cut-to-end-of-line': -> @cutToEndOfLine()
'editor:cut-to-end-of-screen-line': -> @cutToEndOfScreenLine()
'editor:cut-to-end-of-buffer-line': -> @cutToEndOfBufferLine()
'editor:transpose': -> @transpose()
'editor:upper-case': -> @upperCase()
Expand Down
12 changes: 6 additions & 6 deletions src/selection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Selection extends Model

# Public: Selects all the text from the current cursor position to the end of
# the screen line.
selectToEndOfLine: ->
selectToEndOfScreenLine: ->
@modifySelection => @cursor.moveToEndOfScreenLine()

# Public: Selects all the text from the current cursor position to the end of
Expand Down Expand Up @@ -453,12 +453,12 @@ class Selection extends Model
@deleteSelectedText()

# Public: If the selection is empty, removes all text from the cursor to the
# end of the line. If the cursor is already at the end of the line, it
# end of the screen line. If the cursor is already at the end of the line, it
# removes the following newline. If the selection isn't empty, only deletes
# the contents of the selection.
deleteToEndOfLine: ->
deleteToEndOfScreenLine: ->
return @delete() if @isEmpty() and @cursor.isAtEndOfLine()
@selectToEndOfLine() if @isEmpty()
@selectToEndOfScreenLine() if @isEmpty()
@deleteSelectedText()

# Public: Removes the selection or all characters from the start of the
Expand Down Expand Up @@ -577,8 +577,8 @@ class Selection extends Model
@editor.toggleLineCommentsForBufferRows(@getBufferRowRange()...)

# Public: Cuts the selection until the end of the screen line.
cutToEndOfLine: (maintainClipboard) ->
@selectToEndOfLine() if @isEmpty()
cutToEndOfScreenLine: (maintainClipboard) ->
@selectToEndOfScreenLine() if @isEmpty()
@cut(maintainClipboard)

# Public: Cuts the selection until the end of the buffer line.
Expand Down
19 changes: 13 additions & 6 deletions src/text-editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,8 @@ class TextEditor extends Model
# selection; otherwise, deletes all characters of the containing line
# following the cursor. If the cursor is already at the end of the line,
# deletes the following newline.
deleteToEndOfLine: ->
@mutateSelectedText (selection) -> selection.deleteToEndOfLine()
deleteToEndOfScreenLine: ->
@mutateSelectedText (selection) -> selection.deleteToEndOfScreenLine()

# Extended: For each selection, if the selection is empty, delete all characters
# of the containing word following the cursor. Otherwise delete the selected
Expand Down Expand Up @@ -2231,12 +2231,19 @@ class TextEditor extends Model
selectToFirstCharacterOfLine: ->
@expandSelectionsBackward (selection) -> selection.selectToFirstCharacterOfLine()

# Essential: Move the cursor of each selection to the end of its screen line
# while preserving the selection's tail position.
#
# This method may merge selections that end up intersecting.
selectToEndOfScreenLine: ->
@expandSelectionsForward (selection) -> selection.selectToEndOfScreenLine()

# Essential: Move the cursor of each selection to the end of its line while
# preserving the selection's tail position.
#
# This method may merge selections that end up intersecting.
selectToEndOfLine: ->
@expandSelectionsForward (selection) -> selection.selectToEndOfLine()
selectToEndOfBufferLine: ->
@expandSelectionsForward (selection) -> selection.selectToEndOfBufferLine()

# Essential: Expand selections to the beginning of their containing word.
#
Expand Down Expand Up @@ -2877,10 +2884,10 @@ class TextEditor extends Model
# Essential: For each selection, if the selection is empty, cut all characters
# of the containing screen line following the cursor. Otherwise cut the selected
# text.
cutToEndOfLine: ->
cutToEndOfScreenLine: ->
maintainClipboard = false
@mutateSelectedText (selection) ->
selection.cutToEndOfLine(maintainClipboard)
selection.cutToEndOfScreenLine(maintainClipboard)
maintainClipboard = true

# Essential: For each selection, if the selection is empty, cut all characters
Expand Down