mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Take double width chars into account when soft wrapping
This commit is contained in:
@@ -60,6 +60,16 @@ describe "DisplayBuffer", ->
|
||||
changeHandler.reset()
|
||||
|
||||
describe "rendering of soft-wrapped lines", ->
|
||||
describe "when there are double width characters", ->
|
||||
it "takes them into account when finding the soft wrap column", ->
|
||||
displayBuffer.setDoubleWidthCharWidth(5)
|
||||
buffer.setText("私たちのフ是一个地方,数千名学生12345业余爱们的板作为우리포럼hello world this is a pretty long latin line")
|
||||
|
||||
expect(displayBuffer.tokenizedLineForScreenRow(0).text).toBe("私たちのフ是一个地方")
|
||||
expect(displayBuffer.tokenizedLineForScreenRow(1).text).toBe(",数千名学生12345业余爱")
|
||||
expect(displayBuffer.tokenizedLineForScreenRow(2).text).toBe("们的板作为우리포럼hello ")
|
||||
expect(displayBuffer.tokenizedLineForScreenRow(3).text).toBe("world this is a pretty long latin line")
|
||||
|
||||
describe "when editor.softWrapAtPreferredLineLength is set", ->
|
||||
it "uses the preferred line length as the soft wrap column when it is less than the configured soft wrap column", ->
|
||||
atom.config.set('editor.preferredLineLength', 100)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user