diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index fc2c76503..10df357e3 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -130,6 +130,12 @@ describe "DisplayBuffer", -> expect(displayBuffer.tokenizedLineForScreenRow(10).text).toBe ' return ' expect(displayBuffer.tokenizedLineForScreenRow(11).text).toBe ' sort(left).concat(pivot).concat(sort(right));' + it "wraps the line at the boundary if it includes a CJK character", -> + buffer.setTextInRange([[0, 0], [1, 0]], 'abcd efg유私フ业余爱\n') + displayBuffer.setEditorWidthInChars(10) + expect(displayBuffer.tokenizedLineForScreenRow(0).text).toBe 'abcd efg유私' + expect(displayBuffer.tokenizedLineForScreenRow(1).text).toBe 'フ业余爱' + describe "when there is no whitespace before the boundary", -> it "wraps the line exactly at the boundary since there's no more graceful place to wrap it", -> buffer.setTextInRange([[0, 0], [1, 0]], 'abcdefghijklmnopqrstuvwxyz\n') diff --git a/src/tokenized-line.coffee b/src/tokenized-line.coffee index 2a27d3f12..2ff4c3b17 100644 --- a/src/tokenized-line.coffee +++ b/src/tokenized-line.coffee @@ -1,5 +1,5 @@ _ = require 'underscore-plus' -{isPairedCharacter} = require './text-utils' +{isPairedCharacter, isCjkCharacter} = require './text-utils' Token = require './token' {SoftTab, HardTab, PairedCharacter, SoftWrapIndent} = require './special-token-symbols' @@ -321,8 +321,11 @@ class TokenizedLine return unless maxColumn? return unless @text.length > maxColumn - if /\s/.test(@text[maxColumn]) - # search forward for the start of a word past the boundary + if isCjkCharacter(@text[maxColumn]) + # always wrap when a CJK character is at the wrap boundary + return maxColumn + else if /\s/.test(@text[maxColumn]) + # search forward for the start of a word past the boundary for column in [maxColumn..@text.length] return column if /\S/.test(@text[column])