Implement ratioForCharacter

This commit is contained in:
Antonio Scandurra
2016-03-18 14:58:13 +01:00
parent 3c70ff92f4
commit bbcbe9e809

View File

@@ -7,6 +7,7 @@ Model = require './model'
Token = require './token'
Decoration = require './decoration'
LayerDecoration = require './layer-decoration'
{isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter} = require './text-utils'
class BufferToScreenConversionError extends Error
constructor: (@message, @metadata) ->
@@ -120,7 +121,7 @@ class DisplayBuffer extends Model
softWrapColumn: softWrapColumn
showIndentGuides: @config.get('editor.showIndentGuide', scope: scopeDescriptor)
tabLength: @config.get('editor.tabLength', scope: scopeDescriptor),
ratioForCharacter: -> 1.0 # TODO: replace this with korean/double/half width characters.
ratioForCharacter: @ratioForCharacter.bind(this)
})
updateAllScreenLines: ->
@@ -215,6 +216,16 @@ class DisplayBuffer extends Model
getLineHeightInPixels: -> @lineHeightInPixels
setLineHeightInPixels: (@lineHeightInPixels) -> @lineHeightInPixels
ratioForCharacter: (character) ->
if isKoreanCharacter(character)
@getKoreanCharWidth() / @getDefaultCharWidth()
else if isHalfWidthCharacter(character)
@getHalfWidthCharWidth() / @getDefaultCharWidth()
else if isDoubleWidthCharacter(character)
@getDoubleWidthCharWidth() / @getDefaultCharWidth()
else
1
getKoreanCharWidth: -> @koreanCharWidth
getHalfWidthCharWidth: -> @halfWidthCharWidth