Implement isWrapBoundary for DisplayLayer

So that we can correctly soft wrap CJK characters.
This commit is contained in:
Antonio Scandurra
2016-03-18 18:30:35 +01:00
parent bbcbe9e809
commit 0cd6bd19af
3 changed files with 33 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ Model = require './model'
Token = require './token'
Decoration = require './decoration'
LayerDecoration = require './layer-decoration'
{isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter} = require './text-utils'
{isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter, isWrapBoundary} = require './text-utils'
class BufferToScreenConversionError extends Error
constructor: (@message, @metadata) ->
@@ -122,6 +122,7 @@ class DisplayBuffer extends Model
showIndentGuides: @config.get('editor.showIndentGuide', scope: scopeDescriptor)
tabLength: @config.get('editor.tabLength', scope: scopeDescriptor),
ratioForCharacter: @ratioForCharacter.bind(this)
isWrapBoundary: isWrapBoundary
})
updateAllScreenLines: ->

View File

@@ -94,6 +94,13 @@ isCJKCharacter = (character) ->
isHalfWidthCharacter(character) or
isKoreanCharacter(character)
isWordStart = (previousCharacter, character) ->
(previousCharacter is ' ' or previousCharacter is '\t') and
(character isnt ' ' and character isnt '\t')
isWrapBoundary = (previousCharacter, character) ->
isWordStart(previousCharacter, character) or isCJKCharacter(character)
# Does the given string contain at least surrogate pair, variation sequence,
# or combined character?
#
@@ -107,4 +114,8 @@ hasPairedCharacter = (string) ->
index++
false
module.exports = {isPairedCharacter, hasPairedCharacter, isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter, isCJKCharacter}
module.exports = {
isPairedCharacter, hasPairedCharacter,
isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter,
isWrapBoundary
}