From 16e22cd0aa882398e3472e4743c4a9d7fb886f3a Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Sat, 18 Jul 2015 11:41:25 +0000 Subject: [PATCH] Editor: word count: count astrals as one character This makes sure an emoji, for example, is counted as one character. See #30966. git-svn-id: https://develop.svn.wordpress.org/trunk@33320 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/word-count.js | 3 +++ tests/qunit/wp-admin/js/word-count.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/wp-admin/js/word-count.js b/src/wp-admin/js/word-count.js index bdf4adefae..025412e346 100644 --- a/src/wp-admin/js/word-count.js +++ b/src/wp-admin/js/word-count.js @@ -57,6 +57,7 @@ '\u2E00-\u2E7F', ']' ].join( '' ), 'g' ), + astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, wordsRegExp: /\S\s+/g, charactersRegExp: /\S/g, allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g, @@ -82,6 +83,8 @@ if ( type === 'words' ) { text = text.replace( this.settings.connectorRegExp, ' ' ); text = text.replace( this.settings.removeRegExp, '' ); + } else { + text = text.replace( this.settings.astralRegExp, 'a' ); } text = text.match( this.settings[ type + 'RegExp' ] ); diff --git a/tests/qunit/wp-admin/js/word-count.js b/tests/qunit/wp-admin/js/word-count.js index ad69453e49..a31fc09668 100644 --- a/tests/qunit/wp-admin/js/word-count.js +++ b/tests/qunit/wp-admin/js/word-count.js @@ -51,6 +51,13 @@ words: 3, characters: 11, all: 12 + }, + { + message: 'Astrals.', + string: '\uD83D\uDCA9', + words: 1, + characters: 1, + all: 1 } ], function( test ) { _.each( [ 'words', 'characters', 'all' ], function( type ) {