mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Insertions at beginning/end of a fold are considered to be outside it.
Also added a spec where text is changed on a line in between two placeholders and handled correctly.
This commit is contained in:
@@ -140,29 +140,29 @@ class LineFolder
|
||||
_.extend LineFolder.prototype, EventEmitter
|
||||
|
||||
class Fold
|
||||
constructor: (@lineFolder, {start, end}) ->
|
||||
@start = new Anchor(start)
|
||||
@end = new Anchor(end)
|
||||
constructor: (@lineFolder, {@start, @end}) ->
|
||||
|
||||
destroy: ->
|
||||
@lineFolder.destroyFold(this)
|
||||
|
||||
getRange: ->
|
||||
new Range(@start.position, @end.position)
|
||||
new Range(@start, @end)
|
||||
|
||||
handleBufferChange: (event) ->
|
||||
oldStartRow = @start.position.row
|
||||
@start.handleBufferChange(event)
|
||||
@end.handleBufferChange(event)
|
||||
newStartRow = @start.position.row
|
||||
oldStartRow = @start.row
|
||||
@start = @updateAnchorPoint(@start, event)
|
||||
@end = @updateAnchorPoint(@end, event, false)
|
||||
|
||||
if newStartRow != oldStartRow
|
||||
if @start.row != oldStartRow
|
||||
@lineFolder.unregisterFold(oldStartRow, this)
|
||||
@lineFolder.registerFold(newStartRow, this)
|
||||
@lineFolder.registerFold(@start.row, this)
|
||||
|
||||
class Anchor
|
||||
constructor: (@position) ->
|
||||
updateAnchorPoint: (point, event, inclusive=true) ->
|
||||
{ newRange, oldRange } = event
|
||||
if inclusive
|
||||
return point if oldRange.end.isGreaterThan(point)
|
||||
else
|
||||
return point if oldRange.end.isGreaterThanOrEqual(point)
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
@position = e.newRange.end.add(@position.subtract(e.oldRange.end))
|
||||
newRange.end.add(point.subtract(oldRange.end))
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ class Point
|
||||
isGreaterThan: (other) ->
|
||||
@compare(other) > 0
|
||||
|
||||
isGreaterThanOrEqual: (other) ->
|
||||
@compare(other) >= 0
|
||||
|
||||
inspect: ->
|
||||
"(#{@row}, #{@column})"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user