mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
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:
parent
35f1243d32
commit
0bc510ab58
@ -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]
|
||||
|
@ -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...) ->
|
||||
|
@ -114,7 +114,7 @@ class LineFolder
|
||||
@lineMap.lineForScreenRow(screenRow)
|
||||
|
||||
getLines: ->
|
||||
@lineMap.getScreenLines()
|
||||
@lineMap.screenLinesForRows(0, @lastRow())
|
||||
|
||||
lineCount: ->
|
||||
@lineMap.screenLineCount()
|
||||
|
@ -50,14 +50,10 @@ class LineMap
|
||||
replaceScreenRows: (start, end, screenLines) ->
|
||||
@spliceAtScreenRow(start, end - start + 1, screenLines)
|
||||
|
||||
getScreenLines: ->
|
||||
return @screenLines
|
||||
|
||||
lineForScreenRow: (row) ->
|
||||
@linesForScreenRows(row, row)[0]
|
||||
|
||||
linesForScreenRows: (startRow, endRow) ->
|
||||
lastLine = null
|
||||
lines = []
|
||||
delta = new Point
|
||||
|
||||
@ -67,11 +63,13 @@ class LineMap
|
||||
if pendingFragment
|
||||
pendingFragment = pendingFragment.concat(fragment)
|
||||
else
|
||||
pendingFragment = fragment
|
||||
pendingFragment = _.clone(fragment)
|
||||
if pendingFragment.screenDelta.row > 0
|
||||
pendingFragment.bufferDelta = new Point(1, 0)
|
||||
lines.push pendingFragment
|
||||
pendingFragment = null
|
||||
delta = delta.add(fragment.screenDelta)
|
||||
|
||||
lines
|
||||
|
||||
lineForBufferRow: (row) ->
|
||||
|
@ -106,11 +106,14 @@ class LineWrapper
|
||||
@lineMap.linesForScreenRows(startRow, endRow)
|
||||
|
||||
getLines: ->
|
||||
@linesForScreenRows(0, @lineCount() - 1)
|
||||
@linesForScreenRows(0, @lastRow())
|
||||
|
||||
lineCount: ->
|
||||
@lineMap.screenLineCount()
|
||||
|
||||
lastRow: ->
|
||||
@lineCount() - 1
|
||||
|
||||
logLines: (start=0, end=@lineCount() - 1)->
|
||||
@lineMap.logLines(start, end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user