Detect batch selections

This commit is contained in:
Antonio Scandurra
2015-02-24 21:06:26 +01:00
parent c4b54a5a33
commit b2bed7cea8
2 changed files with 55 additions and 13 deletions

View File

@@ -44,7 +44,28 @@ class TextEditorPresenter
@model.setHorizontalScrollbarHeight(@measuredHorizontalScrollbarHeight) if @measuredHorizontalScrollbarHeight?
observeModel: ->
@disposables.add @model.onWillSelectMultiple =>
@multipleSelectionBatch = true
@disposables.add @model.onDidSelectMultiple =>
@multipleSelectionBatch = false
@updateStartRow()
@updateEndRow()
@updateHeightState()
@didStartScrolling()
@updateVerticalScrollState()
@updateHorizontalScrollState()
@updateScrollbarsState()
@updateContentState()
@updateDecorations()
@updateLinesState()
@updateGutterState()
@updateLineNumbersState()
@disposables.add @model.onDidChange =>
return if @multipleSelectionBatch
@updateContentDimensions()
@updateEndRow()
@updateHeightState()
@@ -516,6 +537,8 @@ class TextEditorPresenter
unless @scrollTop is scrollTop or Number.isNaN(scrollTop)
@scrollTop = scrollTop
@model.setScrollTop(scrollTop)
return if @multipleSelectionBatch
@updateStartRow()
@updateEndRow()
@didStartScrolling()
@@ -790,6 +813,8 @@ class TextEditorPresenter
@updateOverlaysState()
didDestroyDecoration: (decoration) ->
return if @multipleSelectionBatch
if decoration.isType('line') or decoration.isType('line-number')
@removeFromLineDecorationCaches(decoration, decoration.getMarker().getScreenRange())
@updateLinesState() if decoration.isType('line')
@@ -810,6 +835,7 @@ class TextEditorPresenter
didAddDecoration: (decoration) ->
@observeDecoration(decoration)
return if @multipleSelectionBatch
if decoration.isType('line') or decoration.isType('line-number')
@addToLineDecorationCaches(decoration, decoration.getMarker().getScreenRange())
@updateLinesState() if decoration.isType('line')

View File

@@ -92,9 +92,10 @@ class TextEditor extends Model
@updateInvisibles()
for marker in @findMarkers(@getSelectionMarkerAttributes())
marker.setProperties(preserveFolds: true)
@addSelection(marker)
@addMultipleSelections =>
for marker in @findMarkers(@getSelectionMarkerAttributes())
marker.setProperties(preserveFolds: true)
@addSelection(marker)
@subscribeToBuffer()
@subscribeToDisplayBuffer()
@@ -987,23 +988,38 @@ class TextEditor extends Model
selection.insertText(fn(text))
selection.setBufferRange(range)
addMultipleSelections: (fn) ->
@emitter.emit "will-select-multiple"
@suppressSelectionMerging = true
fn()
@suppressSelectionMerging = false
@mergeIntersectingSelections()
@emitter.emit "did-select-multiple"
onDidSelectMultiple: (callback) ->
@emitter.on "did-select-multiple", callback
onWillSelectMultiple: (callback) ->
@emitter.on "will-select-multiple", callback
# Split multi-line selections into one selection per line.
#
# Operates on all selections. This method breaks apart all multi-line
# selections to create multiple single-line selections that cumulatively cover
# the same original area.
splitSelectionsIntoLines: ->
for selection in @getSelections()
range = selection.getBufferRange()
continue if range.isSingleLine()
@addMultipleSelections =>
for selection in @getSelections()
range = selection.getBufferRange()
continue if range.isSingleLine()
selection.destroy()
{start, end} = range
@addSelectionForBufferRange([start, [start.row, Infinity]])
{row} = start
while ++row < end.row
@addSelectionForBufferRange([[row, 0], [row, Infinity]])
@addSelectionForBufferRange([[end.row, 0], [end.row, end.column]]) unless end.column is 0
selection.destroy()
{start, end} = range
@addSelectionForBufferRange([start, [start.row, Infinity]])
{row} = start
while ++row < end.row
@addSelectionForBufferRange([[row, 0], [row, Infinity]])
@addSelectionForBufferRange([[end.row, 0], [end.row, end.column]]) unless end.column is 0
# Extended: For each selection, transpose the selected text.
#