mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Selections are only cleared when cursor is explicitly moved
This allows multiple selections to be modified without changes to an earlier selection clearing later selections. It means we can remove the `modifySelections` method from `CompositeSelection` and just call methods on selections in a loop.
This commit is contained in:
@@ -1893,4 +1893,4 @@ describe "Editor", ->
|
||||
|
||||
eventHandler.reset()
|
||||
editor.buffer.setPath("new.txt")
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
@@ -21,7 +21,6 @@ class CompositeCursor
|
||||
cursor = new Cursor(@editor)
|
||||
@cursors.push(cursor)
|
||||
@editor.lines.append(cursor)
|
||||
@editor.addSelectionForCursor(cursor)
|
||||
cursor
|
||||
|
||||
addCursorAtScreenPosition: (screenPosition) ->
|
||||
|
||||
@@ -35,6 +35,7 @@ class CompositeSeleciton
|
||||
selection = new Selection({@editor, cursor})
|
||||
@selections.push(selection)
|
||||
@editor.lines.append(selection)
|
||||
selection
|
||||
|
||||
addSelectionForBufferRange: (bufferRange, options) ->
|
||||
cursor = @editor.compositeCursor.addCursor()
|
||||
@@ -66,26 +67,20 @@ class CompositeSeleciton
|
||||
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)
|
||||
selection.insertText(text) for selection in @getSelections()
|
||||
|
||||
backspace: ->
|
||||
@modifySelectedText (selection) -> selection.backspace()
|
||||
selection.backspace() for selection in @getSelections()
|
||||
|
||||
backspaceToBeginningOfWord: ->
|
||||
@modifySelectedText (selection) -> selection.backspaceToBeginningOfWord()
|
||||
selection.backspaceToBeginningOfWord() for selection in @getSelections()
|
||||
|
||||
delete: ->
|
||||
@modifySelectedText (selection) -> selection.delete()
|
||||
selection.delete() for selection in @getSelections()
|
||||
|
||||
deleteToEndOfWord: ->
|
||||
@modifySelectedText (selection) -> selection.deleteToEndOfWord()
|
||||
selection.deleteToEndOfWord() for selection in @getSelections()
|
||||
|
||||
selectToScreenPosition: (position) ->
|
||||
@getLastSelection().selectToScreenPosition(position)
|
||||
@@ -122,7 +117,7 @@ class CompositeSeleciton
|
||||
|
||||
cut: ->
|
||||
maintainPasteboard = false
|
||||
@modifySelectedText (selection) ->
|
||||
for selection in @getSelections()
|
||||
selection.cut(maintainPasteboard)
|
||||
maintainPasteboard = true
|
||||
|
||||
@@ -140,4 +135,4 @@ class CompositeSeleciton
|
||||
if selection.intersectsWith(otherSelection)
|
||||
selection.merge(otherSelection, options)
|
||||
@mergeIntersectingSelections(options)
|
||||
return
|
||||
return
|
||||
|
||||
@@ -14,6 +14,7 @@ class Cursor extends View
|
||||
|
||||
initialize: (@editor) ->
|
||||
@anchor = new Anchor(@editor)
|
||||
@selection = @editor.compositeSelection.addSelectionForCursor(this)
|
||||
@one 'attach', => @updateAppearance()
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
@@ -31,6 +32,7 @@ class Cursor extends View
|
||||
setBufferPosition: (bufferPosition) ->
|
||||
@anchor.setBufferPosition(bufferPosition)
|
||||
@refreshScreenPosition()
|
||||
@clearSelection()
|
||||
|
||||
getScreenPosition: ->
|
||||
@anchor.getScreenPosition()
|
||||
@@ -38,6 +40,7 @@ class Cursor extends View
|
||||
setScreenPosition: (position, options={}) ->
|
||||
@anchor.setScreenPosition(position, options)
|
||||
@refreshScreenPosition(position, options)
|
||||
@clearSelection()
|
||||
|
||||
refreshScreenPosition: ->
|
||||
@goalColumn = null
|
||||
@@ -48,6 +51,9 @@ class Cursor extends View
|
||||
window.clearTimeout(@idleTimeout) if @idleTimeout
|
||||
@idleTimeout = window.setTimeout (=> @addClass 'idle'), 200
|
||||
|
||||
clearSelection: ->
|
||||
@selection.clearSelection() unless @selection.retainSelection
|
||||
|
||||
getCurrentBufferLine: ->
|
||||
@editor.lineForBufferRow(@getBufferPosition().row)
|
||||
|
||||
|
||||
@@ -16,11 +16,7 @@ class Selection extends View
|
||||
|
||||
initialize: ({@editor, @cursor}) ->
|
||||
@regions = []
|
||||
@cursor.on 'cursor:position-changed', =>
|
||||
if @retainSelection
|
||||
@updateAppearance()
|
||||
else
|
||||
@clearSelection()
|
||||
@cursor.on 'cursor:position-changed', => @updateAppearance()
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
return unless @anchor
|
||||
@@ -106,6 +102,7 @@ class Selection extends View
|
||||
{ text, shouldOutdent } = @autoIndentText(text)
|
||||
@editor.buffer.change(@getBufferRange(), text)
|
||||
@autoOutdentText() if shouldOutdent
|
||||
@clearSelection()
|
||||
|
||||
autoIndentText: (text) ->
|
||||
if @editor.autoIndent
|
||||
|
||||
Reference in New Issue
Block a user