Properly translate positions when wrapper and folder are composed

The key was in LineMap.linesForScreenRows. For each screen line, it
concatenates all line fragments (if there are indeed more than 1) that
traverse that line to return a single line fragment representing the
line. The key was to update the buffer delta for that fragment to
always be 1,0. Because the wrapper is treating the folder as if it's
the buffer, the lines it stores in its map need to traverse only a
single "buffer" line (that's a single line after folds are taken into
account). We may need better language than "screen" and "buffer"
because the wrapper treats the folder as the "buffer" but that's
confusing because it isn't.
This commit is contained in:
Nathan Sobo
2012-02-24 21:56:18 -07:00
parent 35f1243d32
commit 0bc510ab58
5 changed files with 12 additions and 7 deletions

View File

@@ -743,3 +743,5 @@ describe "Editor", ->
expect(editor.selection.isEmpty()).toBeTruthy()
expect(editor.getCursorScreenPosition()).toEqual [4, 32]
editor.setCursorScreenPosition([9, 2])
expect(editor.getCursorScreenPosition()).toEqual [9, 2]

View File

@@ -129,6 +129,7 @@ describe "LineWrapper", ->
it "adjusts the position to account for the fold", ->
fold = folder.createFold(new Range([4, 29], [7, 4]))
expect(wrapper.screenPositionForBufferPosition([7, 4])).toEqual [5, 32]
expect(wrapper.screenPositionForBufferPosition([8, 12])).toEqual [6, 12]
describe ".bufferPositionForScreenPosition(point)", ->
it "translates the given screen position to a buffer position, account for wrapped lines", ->
@@ -147,6 +148,7 @@ describe "LineWrapper", ->
it "adjusts the position to account for the fold", ->
fold = folder.createFold(new Range([4, 29], [7, 4]))
expect(wrapper.bufferPositionForScreenPosition([5, 32])).toEqual [7, 4]
expect(wrapper.bufferPositionForScreenPosition([6, 12])).toEqual [8, 12]
describe ".wrapScreenLine(screenLine)", ->
makeTokens = (tokenValues...) ->