Convert selection and cursor fully over to markers.

This commit is contained in:
Nathan Sobo
2013-02-05 13:39:00 -07:00
parent afe0a6570a
commit 1d30605f7f
8 changed files with 51 additions and 20 deletions

View File

@@ -666,7 +666,7 @@ describe 'Buffer', ->
expect(buffer.positionForCharacterIndex(61)).toEqual [2, 0]
expect(buffer.positionForCharacterIndex(408)).toEqual [12, 2]
fdescribe "markers", ->
describe "markers", ->
describe "marker creation", ->
it "allows markers to be created with ranges and positions", ->
marker1 = buffer.markRange([[4, 20], [4, 23]])
@@ -677,7 +677,7 @@ describe 'Buffer', ->
marker2 = buffer.markPosition([4, 20])
expect(buffer.getMarkerRange(marker2)).toEqual [[4, 20], [4, 20]]
expect(buffer.getMarkerPosition(marker2)).toEqual [4, 20]
expect(buffer.getMarkerTailPosition(marker2)).toBeNull()
expect(buffer.getMarkerTailPosition(marker2)).toEqual [4, 20]
it "allows markers to be created in a reversed orientation", ->
marker = buffer.markRange([[4, 20], [4, 23]], reverse: true)
@@ -713,7 +713,7 @@ describe 'Buffer', ->
expect(buffer.getMarkerRange(marker)).toEqual [[2, 0], [4, 23]]
expect(buffer.isMarkerReversed(marker)).toBeTruthy()
fdescribe ".observeMarker(marker, callback)", ->
describe ".observeMarker(marker, callback)", ->
[observeHandler, marker, subscription] = []
beforeEach ->
@@ -771,7 +771,7 @@ describe 'Buffer', ->
oldHeadPosition: [4, 23]
newHeadPosition: [4, 23]
oldTailPosition: [4, 20]
newTailPosition: null
newTailPosition: [4, 23]
bufferChanged: false
}

View File

@@ -590,7 +590,7 @@ describe "DisplayBuffer", ->
it "returns the length of the longest screen line", ->
expect(displayBuffer.maxLineLength()).toBe 65
fdescribe "markers", ->
describe "markers", ->
beforeEach ->
displayBuffer.foldBufferRow(4)

View File

@@ -46,6 +46,19 @@ 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)

View File

@@ -1096,13 +1096,16 @@ describe "Editor", ->
it "does not autoscroll if the 'autoscroll' option is false", ->
editor.setCursorBufferPosition([11,0])
spyOn(editor, 'scrollToPixelPosition')
editor.setCursorScreenPosition([10, 10], autoscroll: false)
expect(editor.scrollToPixelPosition).not.toHaveBeenCalled()
# autoscrolls on a subsequent change, however
editor.setCursorScreenPosition([10, 10])
it "autoscrolls to cursor if autoscroll is true, even if the position does not change", ->
spyOn(editor, 'scrollToPixelPosition')
editor.setCursorScreenPosition([4, 10], autoscroll: false)
editor.setCursorScreenPosition([4, 10])
expect(editor.scrollToPixelPosition).toHaveBeenCalled()
editor.setCursorBufferPosition([4, 10])
expect(editor.scrollToPixelPosition).toHaveBeenCalled()
describe "when the last cursor exceeds the upper or lower scroll margins", ->

View File

@@ -36,7 +36,7 @@ class BufferMarker
getHeadPosition: -> @headPosition
getTailPosition: -> @tailPosition
getTailPosition: -> @tailPosition ? @getHeadPosition()
setHeadPosition: (newHeadPosition, options={}) ->
oldHeadPosition = @getHeadPosition()
@@ -65,11 +65,12 @@ class BufferMarker
@getRange().end
placeTail: ->
@setTailPosition(@headPosition) unless @tailPosition
@setTailPosition(@getHeadPosition()) unless @tailPosition
clearTail: ->
oldTailPosition = @getTailPosition()
@tailPosition = newTailPosition = null
@tailPosition = null
newTailPosition = @getTailPosition()
@notifyObservers({oldTailPosition, newTailPosition, bufferChanged: false})
tryToInvalidate: (oldRange) ->

View File

@@ -18,18 +18,18 @@ class CursorView extends View
shouldPauseBlinking: false
initialize: (@cursor, @editor) ->
@cursor.on 'moved.cursor-view', ({ autoscroll }) =>
@cursor.on 'moved.cursor-view', =>
@needsUpdate = true
@shouldPauseBlinking = true
@editor.requestDisplayUpdate()
@cursor.on 'visibility-changed.cursor-view', (visible) =>
@needsUpdate = true
@cursor.on 'autoscrolled.cursor-view', =>
@editor.requestDisplayUpdate()
@cursor.on 'destroyed.cursor-view', =>
@needsRemoval = true
@editor.requestDisplayUpdate()
remove: ->
@editor.removeCursorView(this)

View File

@@ -13,9 +13,18 @@ class Cursor
constructor: ({@editSession, @marker}) ->
@editSession.observeMarker @marker, (e) =>
@setVisible(@selection.isEmpty())
@needsAutoscroll ?= @isLastCursor() and !e.bufferChanged
@trigger 'moved', e
@editSession.trigger 'cursor-moved', e
event =
oldBufferPosition: e.oldHeadBufferPosition
oldScreenPosition: e.oldHeadScreenPosition
newBufferPosition: e.newHeadBufferPosition
newScreenPosition: e.newHeadScreenPosition
bufferChanged: e.bufferChanged
@trigger 'moved', event
@editSession.trigger 'cursor-moved', event
@needsAutoscroll = true
destroy: ->
@@ -27,7 +36,10 @@ class Cursor
@goalColumn = null
@clearSelection()
@needsAutoscroll = (options.autoscroll ? true) and @isLastCursor()
@editSession.setMarkerHeadScreenPosition(@marker, screenPosition, options)
if @getScreenPosition().isEqual(screenPosition)
@trigger 'autoscrolled' if @needsAutoscroll
else
@editSession.setMarkerHeadScreenPosition(@marker, screenPosition, options)
getScreenPosition: ->
@editSession.getMarkerHeadScreenPosition(@marker)
@@ -36,7 +48,10 @@ class Cursor
@goalColumn = null
@clearSelection()
@needsAutoscroll = options.autoscroll ? @isLastCursor()
@editSession.setMarkerHeadBufferPosition(@marker, bufferPosition, options)
if @getBufferPosition().isEqual(bufferPosition)
@trigger 'autoscrolled' if @needsAutoscroll
else
@editSession.setMarkerHeadBufferPosition(@marker, bufferPosition, options)
getBufferPosition: ->
@editSession.getMarkerHeadBufferPosition(@marker)
@@ -44,7 +59,7 @@ class Cursor
setVisible: (visible) ->
if @visible != visible
@visible = visible
@needsAutoscroll = @visible and @isLastCursor()
@needsAutoscroll ?= true if @visible and @isLastCursor()
@trigger 'visibility-changed', @visible
isVisible: -> @visible

View File

@@ -68,7 +68,6 @@ class Selection
screenRangeChanged: ->
screenRange = @getScreenRange()
@trigger 'screen-range-changed', screenRange
@cursor?.setVisible(screenRange.isEmpty())
getText: ->
@editSession.buffer.getTextInRange(@getBufferRange())