xxwip
This commit is contained in:
Corey Johnson
2012-04-02 14:55:40 -07:00
parent 7dae03de0d
commit bf5ebc9969
2 changed files with 54 additions and 54 deletions

View File

@@ -7,6 +7,9 @@ class CompositeCursor
@cursors = []
@addCursor()
handleBufferChange: (e) ->
@moveCursors (cursor) -> cursor.handleBufferChange(e)
getCursor: (index) ->
index ?= @cursors.length - 1
@cursors[index]
@@ -81,9 +84,6 @@ class CompositeCursor
moveToFirstCharacterOfLine: ->
@moveCursors (cursor) -> cursor.moveToFirstCharacterOfLine()
handleBufferChange: (e) ->
@moveCursors (cursor) -> cursor.handleBufferChange(e)
mergeCursors: ->
positions = []
for cursor in new Array(@cursors...)

View File

@@ -6,11 +6,18 @@ class CompositeSeleciton
constructor: (@editor) ->
@selections = []
handleBufferChange: (e) ->
selection.handleBufferChange(e) for selection in @getSelections()
getSelection: (index) ->
index ?= @selections.length - 1
@selections[index]
getSelections: -> new Array(@selections...)
getSelections: ->
new Array(@selections...)
getLastSelection: ->
_.last(@selections)
getLastSelectionInBuffer: ->
_.last(@getSelections().sort (a, b) ->
@@ -42,12 +49,31 @@ class CompositeSeleciton
selectionForCursor: (cursor) ->
_.find @selections, (selection) -> selection.cursor == cursor
handleBufferChange: (e) ->
selection.handleBufferChange(e) for selection in @getSelections()
setBufferRange: (bufferRange, options) ->
@getLastSelection().setBufferRange(bufferRange, options)
getBufferRange: (bufferRange) ->
@getLastSelection().getBufferRange()
getText: ->
@getLastSelection().getText()
moveSelectionsForward: (fn) ->
fn(selection) for selection in @getSelections()
@mergeIntersectingSelections()
moveSelectionsBackward: (fn) ->
fn(selection) for selection in @getSelections()
@mergeIntersectingSelections(reverse: true)
modifySelectedText: (fn) ->
selection.retainSelection = true for selection in @getSelections()
for selection in @getSelections()
selection.retainSelection = false
fn(selection)
insertText: (text) ->
@modifySelectedText (selection) ->
selection.insertText(text)
@modifySelectedText (selection) -> selection.insertText(text)
backspace: ->
@modifySelectedText (selection) -> selection.backspace()
@@ -64,71 +90,35 @@ class CompositeSeleciton
selectToScreenPosition: (position) ->
@getLastSelection().selectToScreenPosition(position)
moveSelections: (fn) ->
fn(selection) for selection in @getSelections()
@mergeIntersectingSelections()
reverseMoveSelections: (fn) ->
fn(selection) for selection in @getSelections()
@mergeIntersectingSelections(reverse: true)
selectRight: ->
@moveSelections (selection) => selection.selectRight()
@moveSelectionsForward (selection) => selection.selectRight()
selectLeft: ->
@reverseMoveSelections (selection) => selection.selectLeft()
@moveSelectionsBackward (selection) => selection.selectLeft()
selectUp: ->
@reverseMoveSelections (selection) => selection.selectUp()
@moveSelectionsBackward (selection) => selection.selectUp()
selectDown: ->
@moveSelections (selection) => selection.selectDown()
@moveSelectionsForward (selection) => selection.selectDown()
selectToTop: ->
@reverseMoveSelections (selection) => selection.selectToTop()
@moveSelectionsBackward (selection) => selection.selectToTop()
selectToBottom: ->
@moveSelections (selection) => selection.selectToBottom()
@moveSelectionsForward (selection) => selection.selectToBottom()
selectToBeginningOfLine: ->
@reverseMoveSelections (selection) => selection.selectToBeginningOfLine()
@moveSelectionsBackward (selection) => selection.selectToBeginningOfLine()
selectToEndOfLine: ->
@moveSelections (selection) => selection.selectToEndOfLine()
@moveSelectionsForward (selection) => selection.selectToEndOfLine()
selectToBeginningOfWord: ->
@reverseMoveSelections (selection) => selection.selectToBeginningOfWord()
@moveSelectionsBackward (selection) => selection.selectToBeginningOfWord()
selectToEndOfWord: ->
@moveSelections (selection) => selection.selectToEndOfWord()
setBufferRange: (bufferRange, options) ->
@getLastSelection().setBufferRange(bufferRange, options)
getBufferRange: (bufferRange) ->
@getLastSelection().getBufferRange()
getText: ->
@getLastSelection().getText()
getLastSelection: ->
_.last(@selections)
mergeIntersectingSelections: (options) ->
for selection in @getSelections()
otherSelections = @getSelections()
_.remove(otherSelections, selection)
for otherSelection in otherSelections
if selection.intersectsWith(otherSelection)
selection.merge(otherSelection, options)
@mergeIntersectingSelections(options)
return
modifySelectedText: (fn) ->
selection.retainSelection = true for selection in @getSelections()
for selection in @getSelections()
selection.retainSelection = false
fn(selection)
@moveSelectionsForward (selection) => selection.selectToEndOfWord()
cut: ->
maintainPasteboard = false
@@ -141,3 +131,13 @@ class CompositeSeleciton
for selection in @getSelections()
selection.copy(maintainPasteboard)
maintainPasteboard = true
mergeIntersectingSelections: (options) ->
for selection in @getSelections()
otherSelections = @getSelections()
_.remove(otherSelections, selection)
for otherSelection in otherSelections
if selection.intersectsWith(otherSelection)
selection.merge(otherSelection, options)
@mergeIntersectingSelections(options)
return