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

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-03-28 15:07:44 -07:00
parent a90380bc63
commit 2d85825126
4 changed files with 56 additions and 2 deletions

View File

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

View File

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

View File

@ -106,12 +106,14 @@ class Editor extends View
@on 'close', => @remove(); false
@on 'move-to-top', => @moveCursorToTop()
@on 'select-to-top', => @selectToTop()
@on 'move-to-bottom', => @moveCursorToBottom()
@on 'select-to-bottom', => @selectToBottom()
@on 'move-to-beginning-of-line', => @moveCursorToBeginningOfLine()
@on 'move-to-end-of-line', => @moveCursorToEndOfLine()
@on 'move-to-first-character-of-line', => @moveCursorToFirstCharacterOfLine()
@on 'select-to-top', => @selectToTop()
@on 'select-to-bottom', => @selectToBottom()
@on 'select-to-end-of-line', => @selectToEndOfLine()
@on 'select-to-beginning-of-line', => @selectToBeginningOfLine()
buildCursorAndSelection: ->
@compositeSelection = new CompositeSelection(this)
@ -390,6 +392,8 @@ class Editor extends View
selectDown: -> @compositeSelection.selectDown()
selectToTop: -> @compositeSelection.selectToTop()
selectToBottom: -> @compositeSelection.selectToBottom()
selectToEndOfLine: -> @compositeSelection.selectToEndOfLine()
selectToBeginningOfLine: -> @compositeSelection.selectToBeginningOfLine()
selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position)
clearSelections: -> @compositeSelection.clearSelections()

View File

@ -228,6 +228,14 @@ class Selection extends View
@modifySelection =>
@cursor.setScreenPosition(position)
selectToBeginningOfLine: ->
@modifySelection =>
@cursor.moveToBeginningOfLine()
selectToEndOfLine: ->
@modifySelection =>
@cursor.moveToEndOfLine()
cut: (maintainPasteboard=false) ->
@copy(maintainPasteboard)
@delete()