mirror of
https://github.com/atom/atom.git
synced 2026-02-09 22:24:59 -05:00
Correctly translate buffer positions to screen positions when the buffer has tab chars
This commit is contained in:
@@ -136,7 +136,8 @@ class LineMap
|
||||
targetDelta.column = 0
|
||||
else
|
||||
additionalColumns = sourcePosition.column - sourceDelta.column
|
||||
targetDelta.column += lastLineFragment.clipColumn(additionalColumns, { skipAtomicTokens })
|
||||
additionalColumns = lastLineFragment.translateColumn(sourceDeltaType, targetDeltaType, additionalColumns, { skipAtomicTokens })
|
||||
targetDelta.column += additionalColumns
|
||||
|
||||
targetDelta
|
||||
|
||||
|
||||
@@ -44,24 +44,30 @@ class ScreenLineFragment
|
||||
bufferDelta = @bufferDelta.add(other.bufferDelta)
|
||||
new ScreenLineFragment(tokens, text, screenDelta, bufferDelta, {state: other.state})
|
||||
|
||||
clipColumn: (column, { skipAtomicTokens }) ->
|
||||
translateColumn: (sourceDeltaType, targetDeltaType, sourceColumn, options={}) ->
|
||||
{ skipAtomicTokens } = options
|
||||
textLength = @text.length
|
||||
column = Math.min(column, textLength)
|
||||
sourceColumn = Math.min(sourceColumn, textLength)
|
||||
|
||||
currentColumn = 0
|
||||
currentSourceColumn = 0
|
||||
currentTargetColumn = 0
|
||||
for token in @tokens
|
||||
tokenStartColumn = currentColumn
|
||||
tokenEndColumn = tokenStartColumn + token.value.length
|
||||
break if tokenEndColumn > column
|
||||
currentColumn = tokenEndColumn
|
||||
tokenStartTargetColumn = currentTargetColumn
|
||||
tokenStartSourceColumn = currentSourceColumn
|
||||
tokenEndSourceColumn = currentSourceColumn + token[sourceDeltaType]
|
||||
tokenEndTargetColumn = currentTargetColumn + token[targetDeltaType]
|
||||
break if tokenEndSourceColumn > sourceColumn
|
||||
currentSourceColumn = tokenEndSourceColumn
|
||||
currentTargetColumn = tokenEndTargetColumn
|
||||
|
||||
if token?.isAtomic
|
||||
if skipAtomicTokens and column > tokenStartColumn
|
||||
tokenEndColumn
|
||||
if skipAtomicTokens and sourceColumn > tokenStartSourceColumn
|
||||
tokenEndTargetColumn
|
||||
else
|
||||
tokenStartColumn
|
||||
tokenStartTargetColumn
|
||||
else
|
||||
column
|
||||
remainingColumns = sourceColumn - currentSourceColumn
|
||||
currentTargetColumn + remainingColumns
|
||||
|
||||
isSoftWrapped: ->
|
||||
@screenDelta.row == 1 and @bufferDelta.row == 0
|
||||
|
||||
@@ -4,7 +4,9 @@ class Token
|
||||
type: null
|
||||
isAtomic: null
|
||||
|
||||
constructor: ({@value, @type, @isAtomic}) ->
|
||||
constructor: ({@value, @type, @isAtomic, @bufferDelta}) ->
|
||||
@screenDelta = @value.length
|
||||
@bufferDelta ?= @screenDelta
|
||||
|
||||
isEqual: (other) ->
|
||||
@value == other.value and @type == other.type and !!@isAtomic == !!other.isAtomic
|
||||
@@ -22,4 +24,4 @@ class Token
|
||||
new Token(value: substring, type: @type)
|
||||
|
||||
buildTabToken: (tabText) ->
|
||||
new Token(value: tabText, type: @type, isAtomic: true)
|
||||
new Token(value: tabText, type: @type, bufferDelta: 1, isAtomic: true)
|
||||
|
||||
Reference in New Issue
Block a user