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
This commit is contained in:
parent
c1e158cf87
commit
16e22cd0aa
@ -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' ] );
|
||||
|
@ -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 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user