From 5083c18c843d84b0fae93ad1be27e6bb28a44dac Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 22 Sep 2014 15:37:41 -0700 Subject: [PATCH] Add cursor to onDidChangeCursorPosition event object --- spec/editor-spec.coffee | 14 ++++++++++++++ src/cursor.coffee | 1 + 2 files changed, 15 insertions(+) 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'