Skip to content

Commit 181a23b

Browse files
authored
Allow CJK characters to be treated like words when laying out lines of text (playcanvas#2980)
* allow CJK characters to be treated like words when breaking lines * remove * from CJK regex
1 parent 4a86277 commit 181a23b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/framework/components/element/text-element.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class MeshInfo {
4646
const LINE_BREAK_CHAR = /^[\r\n]$/;
4747
const WHITESPACE_CHAR = /^[ \t]$/;
4848
const WORD_BOUNDARY_CHAR = /^[ \t\-]$/;
49+
const CJK_CHAR = /^[\u4E00-\u9FFF]$/;
4950

5051
// unicode bidi control characters https://en.wikipedia.org/wiki/Unicode_control_characters
5152
const CONTROL_CHARS = [
@@ -885,7 +886,8 @@ class TextElement {
885886
}
886887

887888
var isWordBoundary = WORD_BOUNDARY_CHAR.test(char);
888-
if (isWordBoundary) { // char is space, tab, or dash
889+
var isCJK = CJK_CHAR.test(char);
890+
if (isWordBoundary || isCJK) { // char is space, tab, or dash OR CJK
889891
numWordsThisLine++;
890892
wordStartX = _xMinusTrailingWhitespace;
891893
wordStartIndex = i + 1;

0 commit comments

Comments
 (0)