Finish converting cursors to use markers.

The model layer works at least… haven't tested the view. Will test out
the view once I get the selection model working.
This commit is contained in:
Nathan Sobo
2013-01-31 15:52:28 -07:00
parent ec521b3fd3
commit 628701fd3a
8 changed files with 96 additions and 17 deletions

View File

@@ -727,6 +727,30 @@ describe 'Buffer', ->
buffer.setMarkerHeadPosition(marker, [6, 2])
expect(observeHandler).not.toHaveBeenCalled()
describe "marker destruction", ->
marker = null
beforeEach ->
marker = buffer.markRange([[4, 20], [4, 23]])
it "allows a marker to be destroyed", ->
buffer.destroyMarker(marker)
expect(buffer.getMarkerRange(marker)).toBeUndefined()
it "does not restore invalidated markers that have been destroyed", ->
buffer.delete([[4, 15], [4, 25]])
expect(buffer.getMarkerRange(marker)).toBeUndefined()
buffer.destroyMarker(marker)
buffer.undo()
expect(buffer.getMarkerRange(marker)).toBeUndefined()
# even "stayValid" markers get destroyed properly
marker2 = buffer.markRange([[4, 20], [4, 23]], stayValid: true)
buffer.delete([[4, 15], [4, 25]])
buffer.destroyMarker(marker2)
buffer.undo()
expect(buffer.getMarkerRange(marker2)).toBeUndefined()
describe "marker updates due to buffer changes", ->
[marker1, marker2] = []

View File

@@ -584,7 +584,7 @@ describe "DisplayBuffer", ->
beforeEach ->
displayBuffer.foldBufferRow(4)
describe "creation and manipulation", ->
describe "marker creation and manipulation", ->
it "allows markers to be created in terms of both screen and buffer coordinates", ->
marker1 = displayBuffer.markScreenRange([[5, 4], [5, 10]])
marker2 = displayBuffer.markBufferRange([[8, 4], [8, 10]])
@@ -603,7 +603,15 @@ describe "DisplayBuffer", ->
expect(displayBuffer.isMarkerReversed(marker)).toBeTruthy()
expect(displayBuffer.getMarkerBufferRange(marker)).toEqual [[5, 4], [8, 4]]
describe "observation", ->
it "clips screen positions before assigning them", ->
marker = displayBuffer.markScreenRange([[5, 4], [5, 10]])
displayBuffer.setMarkerHeadScreenPosition(marker, [-5, -4])
expect(displayBuffer.getMarkerBufferRange(marker)).toEqual [[0, 0], [8, 4]]
displayBuffer.setMarkerTailScreenPosition(marker, [-5, -4])
expect(displayBuffer.getMarkerBufferRange(marker)).toEqual [[0, 0], [0, 0]]
describe "marker observation", ->
observeHandler = null
beforeEach ->
@@ -662,3 +670,12 @@ describe "DisplayBuffer", ->
displayBuffer.unfoldBufferRow(4)
expect(observeHandler).not.toHaveBeenCalled()
describe "marker destruction", ->
it "allows markers to be destroyed", ->
marker = displayBuffer.markScreenRange([[5, 4], [5, 10]])
displayBuffer.destroyMarker(marker)
expect(displayBuffer.getMarkerBufferRange(marker)).toBeUndefined()

View File

@@ -76,12 +76,12 @@ describe "EditSession", ->
describe "when the cursor is on the first line", ->
it "moves the cursor to the beginning of the line, but retains the goal column", ->
editSession.setCursorScreenPosition(row: 0, column: 4)
editSession.setCursorScreenPosition([0, 4])
editSession.moveCursorUp()
expect(editSession.getCursorScreenPosition()).toEqual(row: 0, column: 0)
expect(editSession.getCursorScreenPosition()).toEqual([0, 0])
editSession.moveCursorDown()
expect(editSession.getCursorScreenPosition()).toEqual(row: 1, column: 4)
expect(editSession.getCursorScreenPosition()).toEqual([1, 4])
it "merges cursors when they overlap", ->
editSession.addCursorAtScreenPosition([1, 0])
@@ -185,9 +185,9 @@ describe "EditSession", ->
describe "when the cursor is on the last column of a line", ->
describe "when there is a subsequent line", ->
it "wraps to the beginning of the next line", ->
editSession.setCursorScreenPosition(row: 0, column: buffer.lineForRow(0).length)
editSession.setCursorScreenPosition([0, buffer.lineForRow(0).length])
editSession.moveCursorRight()
expect(editSession.getCursorScreenPosition()).toEqual(row: 1, column: 0)
expect(editSession.getCursorScreenPosition()).toEqual [1, 0]
describe "when the cursor is on the last line", ->
it "remains in the same position", ->