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:
Nathan Sobo
2012-02-23 17:08:54 -07:00
parent d229585cd4
commit de5eab13d2
3 changed files with 28 additions and 17 deletions

View File

@@ -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))

View File

@@ -59,6 +59,9 @@ class Point
isGreaterThan: (other) ->
@compare(other) > 0
isGreaterThanOrEqual: (other) ->
@compare(other) >= 0
inspect: ->
"(#{@row}, #{@column})"