Move ScreenLineFragment.splitTokenAt to Token.splitAt

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-05 14:11:12 -06:00
parent 41a90f6caf
commit ef21823e2a
2 changed files with 6 additions and 7 deletions

View File

@@ -22,7 +22,7 @@ class ScreenLineFragment
leftTextLength = 0
while leftTextLength < column
if leftTextLength + rightTokens[0].value.length > column
rightTokens[0..0] = @splitTokenAt(rightTokens[0], column - leftTextLength)
rightTokens[0..0] = rightTokens[0].splitAt(column - leftTextLength)
nextToken = rightTokens.shift()
leftTextLength += nextToken.value.length
leftTokens.push nextToken
@@ -37,12 +37,6 @@ class ScreenLineFragment
rightFragment = new ScreenLineFragment(rightTokens, rightText, rightScreenDelta, rightBufferDelta, {@state})
[leftFragment, rightFragment]
splitTokenAt: (token, splitIndex) ->
{ type, value } = token
value1 = value.substring(0, splitIndex)
value2 = value.substring(splitIndex)
[{value: value1, type }, {value: value2, type}]
concat: (other) ->
tokens = @tokens.concat(other.tokens)
text = @text + other.text

View File

@@ -8,3 +8,8 @@ class Token
isEqual: (other) ->
@value == other.value and @type == other.type and !!@isAtomic == !!other.isAtomic
splitAt: (splitIndex) ->
value1 = @value.substring(0, splitIndex)
value2 = @value.substring(splitIndex)
[new Token(value: value1, type: @type), new Token(value: value2, type: @type)]