mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Editor handles backspace-to-beginning-of-word
This commit is contained in:
@@ -1472,6 +1472,29 @@ describe "Editor", ->
|
||||
editor.trigger keydownEvent('backspace')
|
||||
expect(editor.buffer.lineForRow(0)).toBe 'var qsort = function () {'
|
||||
|
||||
describe "backspace-to-beginning-of-word", ->
|
||||
it "deletes all text between the cursor and the beginning of the word", ->
|
||||
editor.setCursorBufferPosition([1, 24])
|
||||
editor.addCursorAtBufferPosition([2, 5])
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.trigger 'backspace-to-beginning-of-word'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(ems) {'
|
||||
expect(buffer.lineForRow(2)).toBe ' f (items.length <= 1) return items;'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 22]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 4]
|
||||
|
||||
editor.trigger 'backspace-to-beginning-of-word'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = functionems) f (items.length <= 1) return items;'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 21]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1, 26]
|
||||
|
||||
describe "when text is selected", ->
|
||||
it "deletes only selected text", ->
|
||||
editor.setSelectionBufferRange([[1, 24], [1, 27]])
|
||||
editor.trigger 'backspace-to-beginning-of-word'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
|
||||
|
||||
describe "when delete is pressed", ->
|
||||
describe "when the cursor is on the middle of a line", ->
|
||||
it "deletes the character following the cursor", ->
|
||||
|
||||
@@ -57,6 +57,9 @@ class CompositeSeleciton
|
||||
backspace: ->
|
||||
@modifySelectedText (selection) -> selection.backspace()
|
||||
|
||||
backspaceToBeginningOfWord: ->
|
||||
@modifySelectedText (selection) -> selection.backspaceToBeginningOfWord()
|
||||
|
||||
delete: ->
|
||||
@modifySelectedText (selection) -> selection.delete()
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ class Editor extends View
|
||||
@on 'select-down', => @selectDown()
|
||||
@on 'newline', => @insertText("\n")
|
||||
@on 'backspace', => @backspace()
|
||||
@on 'backspace-to-beginning-of-word', => @backspaceToBeginningOfWord()
|
||||
@on 'delete', => @delete()
|
||||
@on 'cut', => @cutSelection()
|
||||
@on 'copy', => @copySelection()
|
||||
@@ -403,6 +404,9 @@ class Editor extends View
|
||||
selectToEndOfWord: -> @compositeSelection.selectToEndOfWord()
|
||||
selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position)
|
||||
clearSelections: -> @compositeSelection.clearSelections()
|
||||
backspace: -> @compositeSelection.backspace()
|
||||
backspaceToBeginningOfWord: -> @compositeSelection.backspaceToBeginningOfWord()
|
||||
delete: -> @compositeSelection.delete()
|
||||
|
||||
setText: (text) -> @buffer.setText(text)
|
||||
getText: -> @buffer.getText()
|
||||
@@ -424,11 +428,6 @@ class Editor extends View
|
||||
|
||||
foldSelection: -> @getSelection().fold()
|
||||
|
||||
backspace: ->
|
||||
@compositeSelection.backspace()
|
||||
|
||||
delete: ->
|
||||
@compositeSelection.delete()
|
||||
|
||||
undo: ->
|
||||
@buffer.undo()
|
||||
|
||||
@@ -129,6 +129,10 @@ class Selection extends View
|
||||
@selectLeft() if @isEmpty()
|
||||
@deleteSelectedText()
|
||||
|
||||
backspaceToBeginningOfWord: ->
|
||||
@selectToBeginningOfWord() if @isEmpty()
|
||||
@deleteSelectedText()
|
||||
|
||||
delete: ->
|
||||
@selectRight() if @isEmpty()
|
||||
@deleteSelectedText()
|
||||
|
||||
Reference in New Issue
Block a user