diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index f196bec78..1c2dfbd13 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -174,6 +174,20 @@ describe "Editor", -> editor.moveDown() expect(editor.getCursorBufferPosition()).toEqual [1, 1] + it "emits an event with the old position, new position, and the cursor that moved", -> + editor.onDidChangeCursorPosition positionChangedHandler = jasmine.createSpy() + + editor.setCursorBufferPosition([2, 4]) + + expect(positionChangedHandler).toHaveBeenCalled() + eventObject = positionChangedHandler.mostRecentCall.args[0] + + expect(eventObject.oldBufferPosition).toEqual [0, 0] + expect(eventObject.oldScreenPosition).toEqual [0, 0] + expect(eventObject.newBufferPosition).toEqual [2, 4] + expect(eventObject.newScreenPosition).toEqual [2, 4] + expect(eventObject.cursor).toBe editor.getLastCursor() + describe ".setCursorScreenPosition(screenPosition)", -> it "clears a goal column established by vertical movement", -> # set a goal column by moving down diff --git a/src/cursor.coffee b/src/cursor.coffee index 112065ff1..488271799 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -42,6 +42,7 @@ class Cursor extends Model newBufferPosition: newHeadBufferPosition newScreenPosition: newHeadScreenPosition textChanged: textChanged + cursor: this @emit 'moved', movedEvent @emitter.emit 'did-change-position'