After shift/arrow-key movement, merge overlapping selections

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-27 11:09:35 -07:00
parent 6b96251174
commit 81869ebf59
6 changed files with 108 additions and 55 deletions

View File

@@ -17,9 +17,9 @@ class CompositeSeleciton
@selections.push(selection)
@editor.lines.append(selection)
addSelectionForBufferRange: (bufferRange) ->
addSelectionForBufferRange: (bufferRange, options) ->
cursor = @editor.compositeCursor.addCursor()
@selectionForCursor(cursor).setBufferRange(bufferRange)
@selectionForCursor(cursor).setBufferRange(bufferRange, options)
removeSelectionForCursor: (cursor) ->
_.remove(@selections, @selectionForCursor(cursor))
@@ -31,32 +31,36 @@ class CompositeSeleciton
selection.handleBufferChange(e) for selection in @getSelections()
insertText: (text) ->
@modifySelections (selection) ->
@modifySelectedText (selection) ->
selection.insertText(text)
backspace: ->
@modifySelections (selection) -> selection.backspace()
@modifySelectedText (selection) -> selection.backspace()
delete: ->
@modifySelections (selection) -> selection.delete()
@modifySelectedText (selection) -> selection.delete()
selectToScreenPosition: (position) ->
@lastSelection().selectToScreenPosition(position)
selectRight: ->
selection.selectRight() for selection in @getSelections()
@mergeIntersectingSelections()
selectLeft: ->
selection.selectLeft() for selection in @getSelections()
@mergeIntersectingSelections()
selectUp: ->
selection.selectUp() for selection in @getSelections()
@mergeIntersectingSelections()
selectDown: ->
selection.selectDown() for selection in @getSelections()
@mergeIntersectingSelections()
setBufferRange: (bufferRange) ->
@lastSelection().setBufferRange(bufferRange)
setBufferRange: (bufferRange, options) ->
@lastSelection().setBufferRange(bufferRange, options)
getBufferRange: (bufferRange) ->
@lastSelection().getBufferRange()
@@ -77,7 +81,7 @@ class CompositeSeleciton
@mergeIntersectingSelections()
return
modifySelections: (fn) ->
modifySelectedText: (fn) ->
selection.retainSelection = true for selection in @getSelections()
for selection in @getSelections()
selection.retainSelection = false
@@ -85,7 +89,7 @@ class CompositeSeleciton
cut: ->
maintainPasteboard = false
@modifySelections (selection) ->
@modifySelectedText (selection) ->
selection.cut(maintainPasteboard)
maintainPasteboard = true

View File

@@ -356,8 +356,8 @@ class Editor extends View
getSelection: (index) -> @compositeSelection.getSelection(index)
getSelectedText: -> @compositeSelection.getSelection().getText()
setSelectionBufferRange: (bufferRange) -> @compositeSelection.setBufferRange(bufferRange)
addSelectionForBufferRange: (bufferRange) -> @compositeSelection.addSelectionForBufferRange(bufferRange)
setSelectionBufferRange: (bufferRange, options) -> @compositeSelection.setBufferRange(bufferRange, options)
addSelectionForBufferRange: (bufferRange, options) -> @compositeSelection.addSelectionForBufferRange(bufferRange, options)
selectRight: -> @compositeSelection.selectRight()
selectLeft: -> @compositeSelection.selectLeft()
selectUp: -> @compositeSelection.selectUp()

View File

@@ -42,7 +42,7 @@ class Range
intersectsWith: (otherRange) ->
if @start.isLessThanOrEqual(otherRange.start)
@end.isGreaterThan(otherRange.start)
@end.isGreaterThanOrEqual(otherRange.start)
else
otherRange.intersectsWith(this)

View File

@@ -81,16 +81,20 @@ class Selection extends View
else
new Range(@cursor.getScreenPosition(), @cursor.getScreenPosition())
setScreenRange: (range) ->
@cursor.setScreenPosition(range.start)
setScreenRange: (range, options={}) ->
{ reverse } = options
{ start, end } = range
[start, end] = [end, start] if reverse
@cursor.setScreenPosition(start)
@modifySelection =>
@cursor.setScreenPosition(range.end)
@cursor.setScreenPosition(end)
getBufferRange: ->
@editor.bufferRangeForScreenRange(@getScreenRange())
setBufferRange: (bufferRange) ->
@setScreenRange(@editor.screenRangeForBufferRange(bufferRange))
setBufferRange: (bufferRange, options) ->
@setScreenRange(@editor.screenRangeForBufferRange(bufferRange), options)
getText: ->
@editor.buffer.getTextInRange @getBufferRange()