Remove ‘cursors-moved’ event

It event was not document only being used in EditorComponent. Due to
our batching strategy, it’s fine to respond to individual
::onDidMoveCursor events.
This commit is contained in:
Nathan Sobo
2014-09-04 09:36:49 -06:00
committed by Ben Ogle
parent 2a81687d38
commit 161edfd15a
3 changed files with 7 additions and 26 deletions

View File

@@ -174,21 +174,6 @@ describe "Editor", ->
editor.moveDown()
expect(editor.getCursorBufferPosition()).toEqual [1, 1]
it "emits a single 'cursors-moved' event for all moved cursors", ->
editor.on 'cursors-moved', cursorsMovedHandler = jasmine.createSpy("cursorsMovedHandler")
editor.moveDown()
expect(cursorsMovedHandler.callCount).toBe 1
cursorsMovedHandler.reset()
editor.addCursorAtScreenPosition([3, 0])
editor.moveDown()
expect(cursorsMovedHandler.callCount).toBe 1
cursorsMovedHandler.reset()
editor.getLastCursor().moveDown()
expect(cursorsMovedHandler.callCount).toBe 1
describe ".setCursorScreenPosition(screenPosition)", ->
it "clears a goal column established by vertical movement", ->
# set a goal column by moving down

View File

@@ -31,7 +31,7 @@ EditorComponent = React.createClass
updateRequested: false
updatesPaused: false
updateRequestedWhilePaused: false
cursorsMoved: false
cursorMoved: false
selectionChanged: false
selectionAdded: false
scrollingVertically: false
@@ -196,16 +196,16 @@ EditorComponent = React.createClass
@props.editor.setMini(newProps.mini)
componentDidUpdate: (prevProps, prevState) ->
cursorsMoved = @cursorsMoved
cursorMoved = @cursorMoved
selectionChanged = @selectionChanged
@pendingChanges.length = 0
@cursorsMoved = false
@cursorMoved = false
@selectionChanged = false
if @props.editor.isAlive()
@updateParentViewFocusedClassIfNeeded(prevState)
@updateParentViewMiniClassIfNeeded(prevState)
@props.parentView.trigger 'cursor:moved' if cursorsMoved
@props.parentView.trigger 'cursor:moved' if cursorMoved
@props.parentView.trigger 'selection:changed' if selectionChanged
@props.parentView.trigger 'editor:display-updated'
@@ -346,7 +346,7 @@ EditorComponent = React.createClass
observeEditor: ->
{editor} = @props
@subscribe editor, 'screen-lines-changed', @onScreenLinesChanged
@subscribe editor, 'cursors-moved', @onCursorsMoved
@subscribe editor.onDidMoveCursor(@onCursorMoved)
@subscribe editor, 'selection-removed selection-screen-range-changed', @onSelectionChanged
@subscribe editor, 'selection-added', @onSelectionAdded
@subscribe editor, 'decoration-added', @onDecorationChanged
@@ -749,8 +749,8 @@ EditorComponent = React.createClass
onStoppedScrollingAfterDelay: null # created lazily
onCursorsMoved: ->
@cursorsMoved = true
onCursorMoved: ->
@cursorMoved = true
@requestUpdate()
onDecorationChanged: ->

View File

@@ -1850,16 +1850,12 @@ class Editor extends Model
@emit 'cursor-removed', cursor
moveCursors: (fn) ->
@movingCursors = true
fn(cursor) for cursor in @getCursors()
@mergeCursors()
@movingCursors = false
@emit 'cursors-moved'
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
mergeCursors: ->