mirror of
https://github.com/atom/atom.git
synced 2026-02-11 07:05:11 -05:00
Don't destroy selection/cursor anchors when encompassed by a change
Add the 'strong' option to anchors. If anchors are 'strong' instead of being destroyed by encompassing changes they move to the beginning of the change range.
This commit is contained in:
@@ -9,14 +9,17 @@ class Anchor
|
||||
screenPosition: null
|
||||
|
||||
constructor: (@editSession, options = {}) ->
|
||||
{ @ignoreEqual } = options
|
||||
{ @ignoreEqual, @strong } = options
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
{ oldRange, newRange } = e
|
||||
position = @getBufferPosition()
|
||||
|
||||
if oldRange.containsPoint(position, exclusive: true)
|
||||
@destroy()
|
||||
if @strong
|
||||
@setBufferPosition(oldRange.start)
|
||||
else
|
||||
@destroy()
|
||||
return
|
||||
|
||||
if @ignoreEqual
|
||||
|
||||
@@ -12,7 +12,7 @@ class Cursor
|
||||
wordRegex: /(\w+)|([^\w\s]+)/g
|
||||
|
||||
constructor: ({@editSession, screenPosition, bufferPosition}) ->
|
||||
@anchor = @editSession.addAnchor()
|
||||
@anchor = @editSession.addAnchor(strong: true)
|
||||
@anchor.on 'change-screen-position', (args...) => @trigger 'change-screen-position', args...
|
||||
@setScreenPosition(screenPosition) if screenPosition
|
||||
@setBufferPosition(bufferPosition) if bufferPosition
|
||||
|
||||
@@ -226,7 +226,7 @@ class Selection
|
||||
@trigger 'change-screen-range', newScreenRange unless oldScreenRange.isEqual(newScreenRange)
|
||||
|
||||
placeAnchor: ->
|
||||
@anchor = @editSession.addAnchor()
|
||||
@anchor = @editSession.addAnchor(strong: true)
|
||||
@anchor.setScreenPosition(@cursor.getScreenPosition())
|
||||
@anchor.on 'change-screen-position.selection', => @trigger 'change-screen-range'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user