mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add Editor::onDidMoveCursor
This commit is contained in:
@@ -793,19 +793,20 @@ describe "Editor", ->
|
||||
editor.setCursorBufferPosition([3, 1])
|
||||
expect(editor.getCurrentParagraphBufferRange()).toBeUndefined()
|
||||
|
||||
describe "cursor-moved events", ->
|
||||
describe "::onDidMoveCursor", ->
|
||||
cursorMovedHandler = null
|
||||
|
||||
beforeEach ->
|
||||
editor.foldBufferRow(4)
|
||||
editor.setSelectedBufferRange([[8, 1], [9, 0]])
|
||||
cursorMovedHandler = jasmine.createSpy("cursorMovedHandler")
|
||||
editor.on 'cursor-moved', cursorMovedHandler
|
||||
editor.onDidMoveCursor(cursorMovedHandler)
|
||||
|
||||
describe "when the position of the cursor changes", ->
|
||||
it "emits a cursor-moved event", ->
|
||||
it "notifies observers", ->
|
||||
buffer.insert([9, 0], '...')
|
||||
expect(cursorMovedHandler).toHaveBeenCalledWith(
|
||||
cursor: editor.getLastCursor()
|
||||
oldBufferPosition: [9, 0]
|
||||
oldScreenPosition: [6, 0]
|
||||
newBufferPosition: [9, 3]
|
||||
@@ -814,7 +815,7 @@ describe "Editor", ->
|
||||
)
|
||||
|
||||
describe "when the position of the associated selection's tail changes, but not the cursor's position", ->
|
||||
it "does not emit a cursor-moved event", ->
|
||||
it "does not notify observers", ->
|
||||
buffer.insert([8, 0], '...')
|
||||
expect(cursorMovedHandler).not.toHaveBeenCalled()
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class Cursor extends Model
|
||||
textChanged: textChanged
|
||||
|
||||
@emit 'moved', movedEvent
|
||||
@editor.cursorMoved(movedEvent)
|
||||
@editor.cursorMoved(this, movedEvent)
|
||||
@marker.on 'destroyed', =>
|
||||
@destroyed = true
|
||||
@editor.removeCursor(this)
|
||||
|
||||
@@ -318,6 +318,9 @@ class Editor extends Model
|
||||
onDidInsertText: (callback) ->
|
||||
@emitter.on 'did-insert-text', callback
|
||||
|
||||
onDidMoveCursor: (callback) ->
|
||||
@emitter.on 'did-move-cursor', callback
|
||||
|
||||
# Retrieves the current {TextBuffer}.
|
||||
getBuffer: -> @buffer
|
||||
|
||||
@@ -1853,8 +1856,9 @@ class Editor extends Model
|
||||
@movingCursors = false
|
||||
@emit 'cursors-moved'
|
||||
|
||||
cursorMoved: (event) ->
|
||||
cursorMoved: (cursor, event) ->
|
||||
@emit 'cursor-moved', event
|
||||
@emitter.emit 'did-move-cursor', _.extend({cursor}, event)
|
||||
@emit 'cursors-moved' unless @movingCursors
|
||||
|
||||
# Merge cursors that have the same screen position
|
||||
|
||||
Reference in New Issue
Block a user