Merge cursors after buffer changes that didn't occur via the EditSession

The buffer now emits a new event 'update-anchors-after-change' to signal that all the anchors have been updated, which is an appropriate time to merge cursors.
This commit is contained in:
Nathan Sobo
2012-07-17 10:38:01 -06:00
parent 512c1bfdb9
commit 1d21de1e83
3 changed files with 7 additions and 7 deletions

View File

@@ -1362,14 +1362,12 @@ describe "EditSession", ->
[cursor1, cursor2, cursor3] = editSession.getCursors()
expect(editSession.getCursors().length).toBe 3
editSession.backspace()
buffer.delete([[0, 0], [0, 1]])
expect(editSession.getCursors().length).toBe 2
expect(editSession.getCursors()).toEqual [cursor1, cursor3]
expect(cursor1.getBufferPosition()).toEqual [0,0]
expect(cursor3.getBufferPosition()).toEqual [1,0]
editSession.insertText "x"
expect(editSession.lineForBufferRow(0)).toBe "xar quicksort = function () {"
expect(editSession.lineForBufferRow(1)).toBe "x var sort = function(items) {"
expect(cursor3.getBufferPosition()).toEqual [1,1]
describe "folding", ->
describe "structural folding", ->

View File

@@ -42,6 +42,7 @@ class BufferChangeOperation
event = { oldRange, newRange, oldText, newText }
@buffer.trigger 'change', event
anchor.handleBufferChange(event) for anchor in @buffer.getAnchors()
@buffer.trigger 'update-anchors-after-change'
newRange
calculateNewRange: (oldRange, newText) ->

View File

@@ -45,7 +45,8 @@ class EditSession
@buffer.on "path-change.edit-session-#{@id}", =>
@trigger 'buffer-path-change'
@buffer.on "change.edit-session-#{@id}", (e) => @mergeCursors()
@buffer.on "update-anchors-after-change.edit-session-#{@id}", =>
@mergeCursors()
@displayBuffer.on "change.edit-session-#{@id}", (e) =>
@trigger 'screen-lines-change', e