mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-22 00:19:24 +03:00
Editor handles delete-to-end-of-word, plus alt-d and alt-delete bindings for it
This commit is contained in:
parent
17db025efb
commit
b9cec3cd94
@ -1473,21 +1473,22 @@ describe "Editor", ->
|
||||
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()
|
||||
describe "when no text is selected", ->
|
||||
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 = 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]
|
||||
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", ->
|
||||
@ -1520,6 +1521,31 @@ describe "Editor", ->
|
||||
editor.trigger keydownEvent('delete')
|
||||
expect(buffer.lineForRow(12)).toBe '};'
|
||||
|
||||
describe "delete-to-end-of-word", ->
|
||||
describe "when no text is selected", ->
|
||||
it "deletes to the end of the word", ->
|
||||
editor.setCursorBufferPosition([1, 24])
|
||||
editor.addCursorAtBufferPosition([2, 5])
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.trigger 'delete-to-end-of-word'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
|
||||
expect(buffer.lineForRow(2)).toBe ' i (items.length <= 1) return items;'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 24]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 5]
|
||||
|
||||
editor.trigger 'delete-to-end-of-word'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(it {'
|
||||
expect(buffer.lineForRow(2)).toBe ' iitems.length <= 1) return items;'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 24]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 5]
|
||||
|
||||
describe "when text is selected", ->
|
||||
it "deletes only selected text", ->
|
||||
editor.setSelectionBufferRange([[1, 24], [1, 27]])
|
||||
editor.trigger 'delete-to-end-of-word'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
|
||||
|
||||
describe "when undo/redo events are triggered on the editor", ->
|
||||
it "undoes/redoes the last change", ->
|
||||
buffer.insert [0, 0], "foo"
|
||||
|
@ -58,6 +58,9 @@ class CompositeSeleciton
|
||||
delete: ->
|
||||
@modifySelectedText (selection) -> selection.delete()
|
||||
|
||||
deleteToEndOfWord: ->
|
||||
@modifySelectedText (selection) -> selection.deleteToEndOfWord()
|
||||
|
||||
selectToScreenPosition: (position) ->
|
||||
@getLastSelection().selectToScreenPosition(position)
|
||||
|
||||
|
@ -93,6 +93,7 @@ class Editor extends View
|
||||
@on 'backspace', => @backspace()
|
||||
@on 'backspace-to-beginning-of-word', => @backspaceToBeginningOfWord()
|
||||
@on 'delete', => @delete()
|
||||
@on 'delete-to-end-of-word', => @deleteToEndOfWord()
|
||||
@on 'cut', => @cutSelection()
|
||||
@on 'copy', => @copySelection()
|
||||
@on 'paste', => @paste()
|
||||
@ -407,6 +408,7 @@ class Editor extends View
|
||||
backspace: -> @compositeSelection.backspace()
|
||||
backspaceToBeginningOfWord: -> @compositeSelection.backspaceToBeginningOfWord()
|
||||
delete: -> @compositeSelection.delete()
|
||||
deleteToEndOfWord: -> @compositeSelection.deleteToEndOfWord()
|
||||
|
||||
setText: (text) -> @buffer.setText(text)
|
||||
getText: -> @buffer.getText()
|
||||
|
@ -12,3 +12,4 @@ window.keymap.bindKeys '.editor'
|
||||
'alt-shift-left': 'select-to-beginning-of-word'
|
||||
'alt-shift-right': 'select-to-end-of-word'
|
||||
'alt-backspace': 'backspace-to-beginning-of-word'
|
||||
'alt-delete': 'delete-to-end-of-word'
|
||||
|
@ -10,3 +10,4 @@ window.keymap.bindKeys '.editor',
|
||||
'ctrl-h': 'backspace'
|
||||
'ctrl-d': 'delete'
|
||||
'alt-h': 'backspace-to-beginning-of-word'
|
||||
'alt-d': 'delete-to-end-of-word'
|
||||
|
@ -137,6 +137,10 @@ class Selection extends View
|
||||
@selectRight() if @isEmpty()
|
||||
@deleteSelectedText()
|
||||
|
||||
deleteToEndOfWord: ->
|
||||
@selectToEndOfWord() if @isEmpty()
|
||||
@deleteSelectedText()
|
||||
|
||||
deleteSelectedText: ->
|
||||
range = @getBufferRange()
|
||||
@editor.buffer.delete(range) unless range.isEmpty()
|
||||
|
Loading…
Reference in New Issue
Block a user