Take double width chars into account when soft wrapping

This commit is contained in:
Antonio Scandurra
2015-10-15 16:24:08 +02:00
parent b2a7f4a28e
commit c2ee942df1
3 changed files with 26 additions and 1 deletions

View File

@@ -195,6 +195,12 @@ class DisplayBuffer extends Model
@defaultCharWidth = defaultCharWidth
defaultCharWidth
getDoubleWidthCharWidth: -> @doubleWidthCharWidth
setDoubleWidthCharWidth: (doubleWidthCharWidth) ->
if doubleWidthCharWidth isnt @doubleWidthCharWidth
@doubleWidthCharWidth = doubleWidthCharWidth
doubleWidthCharWidth
getCursorWidth: -> 1
scrollToScreenRange: (screenRange, options = {}) ->
@@ -282,8 +288,13 @@ class DisplayBuffer extends Model
else
charLength = 1
charWidth = @getDefaultCharWidth()
if iterator.hasDoubleWidthCharacterAt(textIndex)
charWidth = @getDoubleWidthCharWidth()
else
charWidth = @getDefaultCharWidth()
return column if currentWidth + charWidth > lineMaxWidth
currentWidth += charWidth
column += charLength
textIndex += charLength

View File

@@ -1,4 +1,5 @@
{SoftTab, HardTab, PairedCharacter, SoftWrapIndent} = require './special-token-symbols'
{isDoubleWidthCharacter} = require './text-utils'
module.exports =
class TokenIterator
@@ -82,5 +83,8 @@ class TokenIterator
isPairedCharacter: ->
@line.specialTokens[@index] is PairedCharacter
hasDoubleWidthCharacterAt: (charIndex) ->
isDoubleWidthCharacter(@getText()[charIndex])
isAtomic: ->
@isSoftTab() or @isHardTab() or @isSoftWrapIndentation() or @isPairedCharacter()