mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Don't emit a cursor-moved event when only the tail of the marker moves
This commit is contained in:
@@ -46,19 +46,6 @@ describe "EditSession", ->
|
||||
expect(editSession.getCursors()).toEqual [cursor1]
|
||||
expect(editSession.getCursorScreenPosition()).toEqual [4, 7]
|
||||
|
||||
it "emits a cursor-moved event with the old and new positions in both coordinates", ->
|
||||
cursorMovedHandler = jasmine.createSpy("cursorMovedHandler")
|
||||
editSession.on 'cursor-moved', cursorMovedHandler
|
||||
editSession.foldBufferRow(4)
|
||||
editSession.setCursorScreenPosition([5, 1])
|
||||
expect(cursorMovedHandler).toHaveBeenCalledWith(
|
||||
oldBufferPosition: [0, 0]
|
||||
oldScreenPosition: [0, 0]
|
||||
newBufferPosition: [8, 0]
|
||||
newScreenPosition: [5, 0]
|
||||
bufferChanged: false
|
||||
)
|
||||
|
||||
describe "when soft-wrap is enabled and code is folded", ->
|
||||
beforeEach ->
|
||||
editSession.setSoftWrapColumn(50)
|
||||
@@ -335,7 +322,6 @@ describe "EditSession", ->
|
||||
editSession.moveCursorToEndOfWord()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [11, 8]
|
||||
|
||||
|
||||
describe ".getCurrentParagraphBufferRange()", ->
|
||||
it "returns the buffer range of the current paragraph, delimited by blank lines or the beginning / end of the file", ->
|
||||
buffer.setText """
|
||||
@@ -366,6 +352,31 @@ describe "EditSession", ->
|
||||
editSession.setCursorBufferPosition([3, 1])
|
||||
expect(editSession.getCurrentParagraphBufferRange()).toBeUndefined()
|
||||
|
||||
describe "cursor-moved events", ->
|
||||
cursorMovedHandler = null
|
||||
|
||||
beforeEach ->
|
||||
editSession.foldBufferRow(4)
|
||||
editSession.setSelectedBufferRange([[8, 1], [9, 0]])
|
||||
cursorMovedHandler = jasmine.createSpy("cursorMovedHandler")
|
||||
editSession.on 'cursor-moved', cursorMovedHandler
|
||||
|
||||
describe "when the position of the cursor changes", ->
|
||||
it "emits a cursor-moved event", ->
|
||||
buffer.insert([9, 0], '...')
|
||||
expect(cursorMovedHandler).toHaveBeenCalledWith(
|
||||
oldBufferPosition: [9, 0]
|
||||
oldScreenPosition: [6, 0]
|
||||
newBufferPosition: [9, 3]
|
||||
newScreenPosition: [6, 3]
|
||||
bufferChanged: true
|
||||
)
|
||||
|
||||
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", ->
|
||||
buffer.insert([8, 0], '...')
|
||||
expect(cursorMovedHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "selection", ->
|
||||
selection = null
|
||||
|
||||
|
||||
@@ -13,18 +13,24 @@ class Cursor
|
||||
|
||||
constructor: ({@editSession, @marker}) ->
|
||||
@editSession.observeMarker @marker, (e) =>
|
||||
{oldHeadScreenPosition, newHeadScreenPosition} = e
|
||||
{oldHeadBufferPosition, newHeadBufferPosition} = e
|
||||
{bufferChanged} = e
|
||||
|
||||
return if oldHeadScreenPosition.isEqual(newHeadScreenPosition)
|
||||
|
||||
@setVisible(@selection.isEmpty())
|
||||
@needsAutoscroll ?= @isLastCursor() and !e.bufferChanged
|
||||
@needsAutoscroll ?= @isLastCursor() and !bufferChanged
|
||||
|
||||
event =
|
||||
oldBufferPosition: e.oldHeadBufferPosition
|
||||
oldScreenPosition: e.oldHeadScreenPosition
|
||||
newBufferPosition: e.newHeadBufferPosition
|
||||
newScreenPosition: e.newHeadScreenPosition
|
||||
bufferChanged: e.bufferChanged
|
||||
movedEvent =
|
||||
oldBufferPosition: oldHeadBufferPosition
|
||||
oldScreenPosition: oldHeadScreenPosition
|
||||
newBufferPosition: newHeadBufferPosition
|
||||
newScreenPosition: newHeadScreenPosition
|
||||
bufferChanged: bufferChanged
|
||||
|
||||
@trigger 'moved', event
|
||||
@editSession.trigger 'cursor-moved', event
|
||||
@trigger 'moved', movedEvent
|
||||
@editSession.trigger 'cursor-moved', movedEvent
|
||||
@needsAutoscroll = true
|
||||
|
||||
destroy: ->
|
||||
|
||||
Reference in New Issue
Block a user