mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Fix linemap translation when an atomic token is at the end of a line.
Previously, if you entered an atomic token (like a tab) on an empty line it would not position the cursor after the token. This commit fixes that. If the last screen line token is atomic, and screenLine.translateColumn's sourceColumn parameter is greater than the start position of the atomic token, then the translated column should be the end position of the atomic token.
This commit is contained in:
@@ -6,8 +6,8 @@ describe "ScreenLine", ->
|
||||
[editSession, buffer, tabText, screenLine, tokenizedBuffer] = []
|
||||
|
||||
beforeEach ->
|
||||
tabText = ' '
|
||||
editSession = fixturesProject.buildEditSessionForPath('sample.js')
|
||||
tabText = '••'
|
||||
editSession = fixturesProject.buildEditSessionForPath('sample.js', { tabText } )
|
||||
{ buffer, tokenizedBuffer } = editSession
|
||||
screenLine = tokenizedBuffer.lineForScreenRow(3)
|
||||
|
||||
@@ -81,8 +81,7 @@ describe "ScreenLine", ->
|
||||
|
||||
describe ".translateColumn(sourceDeltaType, targetDeltaType, sourceColumn, skipAtomicTokens: false)", ->
|
||||
beforeEach ->
|
||||
buffer.insert([0, 13], '\t')
|
||||
buffer.insert([0, 0], '\t\t')
|
||||
buffer.setText("\t\t-")
|
||||
screenLine = tokenizedBuffer.lineForScreenRow(0)
|
||||
|
||||
describe "when translating from buffer to screen coordinates", ->
|
||||
@@ -91,8 +90,11 @@ describe "ScreenLine", ->
|
||||
expect(screenLine.translateColumn('bufferDelta', 'screenDelta', 1)).toBe 2
|
||||
expect(screenLine.translateColumn('bufferDelta', 'screenDelta', 2)).toBe 4
|
||||
expect(screenLine.translateColumn('bufferDelta', 'screenDelta', 3)).toBe 5
|
||||
expect(screenLine.translateColumn('bufferDelta', 'screenDelta', 15)).toBe 17
|
||||
expect(screenLine.translateColumn('bufferDelta', 'screenDelta', 16)).toBe 19
|
||||
|
||||
describe "when an atomic token is at the end of the line (regression)", ->
|
||||
it "translates a buffer position correctly", ->
|
||||
buffer.setText("\t")
|
||||
expect(tokenizedBuffer.lineForScreenRow(0).translateColumn('bufferDelta', 'screenDelta', 1)).toBe 2
|
||||
|
||||
describe "when translating from screen coordinates to buffer coordinates", ->
|
||||
describe "when skipAtomicTokens is false (the default)", ->
|
||||
|
||||
@@ -61,16 +61,19 @@ class ScreenLine
|
||||
|
||||
currentSourceColumn = 0
|
||||
currentTargetColumn = 0
|
||||
isSourceColumnBeforeLastToken = false
|
||||
for token in @tokens
|
||||
tokenStartTargetColumn = currentTargetColumn
|
||||
tokenStartSourceColumn = currentSourceColumn
|
||||
tokenEndSourceColumn = currentSourceColumn + token[sourceDeltaType]
|
||||
tokenEndTargetColumn = currentTargetColumn + token[targetDeltaType]
|
||||
break if tokenEndSourceColumn > sourceColumn
|
||||
if tokenEndSourceColumn > sourceColumn
|
||||
isSourceColumnBeforeLastToken = true
|
||||
break
|
||||
currentSourceColumn = tokenEndSourceColumn
|
||||
currentTargetColumn = tokenEndTargetColumn
|
||||
|
||||
if token?.isAtomic
|
||||
if isSourceColumnBeforeLastToken and token?.isAtomic
|
||||
if skipAtomicTokens and sourceColumn > tokenStartSourceColumn
|
||||
tokenEndTargetColumn
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user