Add select-to-end-of-word and select-to-beginning-of-word

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-29 09:53:18 -07:00
parent 88c4705f8a
commit 90ebbe80e6
5 changed files with 63 additions and 5 deletions

View File

@@ -875,7 +875,7 @@ describe "Editor", ->
expect(editor.getSelection().isReversed()).toBeFalsy()
describe "select-to-beginning-of-line", ->
it "selects text from cusor position to end of line", ->
it "selects text from cusor position to beginning of line", ->
editor.setCursorScreenPosition [12,2]
editor.addCursorAtScreenPosition [11,3]
editor.trigger 'select-to-beginning-of-line'
@@ -908,6 +908,40 @@ describe "Editor", ->
expect(selection2.getBufferRange()).toEqual [[11,3], [11,44]]
expect(selection2.isReversed()).toBeFalsy()
describe "select-to-beginning-of-word", ->
it "selects text from cusor position to beginning of word", ->
editor.setCursorScreenPosition [0,13]
editor.addCursorAtScreenPosition [3,49]
editor.trigger 'select-to-beginning-of-word'
expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,4]
expect(cursor2.getBufferPosition()).toEqual [3,47]
expect(editor.getSelections().length).toBe 2
[selection1, selection2] = editor.getSelections()
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
expect(selection1.isReversed()).toBeTruthy()
expect(selection2.getBufferRange()).toEqual [[3,47], [3,49]]
expect(selection2.isReversed()).toBeTruthy()
describe "select-to-end-of-word", ->
it "selects text from cusor position to end of word", ->
editor.setCursorScreenPosition [0,4]
editor.addCursorAtScreenPosition [3,48]
editor.trigger 'select-to-end-of-word'
expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,13]
expect(cursor2.getBufferPosition()).toEqual [3,50]
expect(editor.getSelections().length).toBe 2
[selection1, selection2] = editor.getSelections()
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
expect(selection1.isReversed()).toBeFalsy()
expect(selection2.getBufferRange()).toEqual [[3,48], [3,50]]
expect(selection2.isReversed()).toBeFalsy()
describe "multiple cursors", ->
it "places multiple cursor with meta-click", ->
editor.attachToDom()

View File

@@ -95,6 +95,14 @@ class CompositeSeleciton
selection.selectToEndOfLine() for selection in @getSelections()
@mergeIntersectingSelections()
selectToBeginningOfWord: ->
selection.selectToBeginningOfWord() for selection in @getSelections()
@mergeIntersectingSelections reverse: true
selectToEndOfWord: ->
selection.selectToEndOfWord() for selection in @getSelections()
@mergeIntersectingSelections()
setBufferRange: (bufferRange, options) ->
@getLastSelection().setBufferRange(bufferRange, options)

View File

@@ -116,6 +116,8 @@ class Editor extends View
@on 'select-to-bottom', => @selectToBottom()
@on 'select-to-end-of-line', => @selectToEndOfLine()
@on 'select-to-beginning-of-line', => @selectToBeginningOfLine()
@on 'select-to-end-of-word', => @selectToEndOfWord()
@on 'select-to-beginning-of-word', => @selectToBeginningOfWord()
buildCursorAndSelection: ->
@compositeSelection = new CompositeSelection(this)
@@ -395,8 +397,10 @@ class Editor extends View
selectDown: -> @compositeSelection.selectDown()
selectToTop: -> @compositeSelection.selectToTop()
selectToBottom: -> @compositeSelection.selectToBottom()
selectToEndOfLine: -> @compositeSelection.selectToEndOfLine()
selectToBeginningOfLine: -> @compositeSelection.selectToBeginningOfLine()
selectToEndOfLine: -> @compositeSelection.selectToEndOfLine()
selectToBeginningOfWord: -> @compositeSelection.selectToBeginningOfWord()
selectToEndOfWord: -> @compositeSelection.selectToEndOfWord()
selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position)
clearSelections: -> @compositeSelection.clearSelections()

View File

@@ -1,9 +1,13 @@
window.keymap.bindKeys '.editor'
'meta-up': 'move-to-top'
'meta-shift-up': 'select-to-top'
'meta-down': 'move-to-bottom'
'meta-shift-down': 'select-to-bottom'
'meta-right': 'move-to-end-of-line'
'meta-left': 'move-to-beginning-of-line'
'alt-left': 'move-to-beginning-of-word'
'alt-right': 'move-to-end-of-word'
'alt-right': 'move-to-end-of-word'
'shift-meta-up': 'select-to-top'
'shift-meta-down': 'select-to-bottom'
'shift-meta-left': 'select-to-beginning-of-line'
'shift-meta-right': 'select-to-end-of-line'
'shift-alt-left': 'select-to-beginning-of-word'
'shift-alt-right': 'select-to-end-of-word'

View File

@@ -236,6 +236,14 @@ class Selection extends View
@modifySelection =>
@cursor.moveToEndOfLine()
selectToBeginningOfWord: ->
@modifySelection =>
@cursor.moveToBeginningOfWord()
selectToEndOfWord: ->
@modifySelection =>
@cursor.moveToEndOfWord()
cut: (maintainPasteboard=false) ->
@copy(maintainPasteboard)
@delete()