@@ -15,18 +15,19 @@ See the License for the specific language governing permissions and
15
15
limitations under the License.
16
16
*/
17
17
18
- import { split } from "lodash" ;
19
18
import EMOJIBASE_REGEX from "emojibase-regex" ;
20
19
import { MatrixClient } from "matrix-js-sdk/src/client" ;
21
20
import { RoomMember } from "matrix-js-sdk/src/models/room-member" ;
22
21
import { Room } from "matrix-js-sdk/src/models/room" ;
22
+ import GraphemeSplitter from "grapheme-splitter" ;
23
23
24
24
import AutocompleteWrapperModel , { GetAutocompleterComponent , UpdateCallback , UpdateQuery } from "./autocomplete" ;
25
25
import { unicodeToShortcode } from "../HtmlUtils" ;
26
26
import * as Avatar from "../Avatar" ;
27
27
import defaultDispatcher from "../dispatcher/dispatcher" ;
28
28
import { Action } from "../dispatcher/actions" ;
29
29
import SettingsStore from "../settings/SettingsStore" ;
30
+ import { getFirstGrapheme } from "../utils/strings" ;
30
31
31
32
const REGIONAL_EMOJI_SEPARATOR = String . fromCodePoint ( 0x200b ) ;
32
33
@@ -133,8 +134,7 @@ abstract class BasePart {
133
134
// To only need to grapheme split the bits of the string we're working on.
134
135
let buffer = str ;
135
136
while ( buffer ) {
136
- // We use lodash's grapheme splitter to avoid breaking apart compound emojis
137
- const [ char ] = split ( buffer , "" , 2 ) ;
137
+ const char = getFirstGrapheme ( buffer ) ;
138
138
if ( ! this . acceptsInsertion ( char , offset + str . length - buffer . length , inputType ) ) {
139
139
break ;
140
140
}
@@ -562,8 +562,7 @@ export class PartCreator {
562
562
case "\n" :
563
563
return new NewlinePart ( ) ;
564
564
default :
565
- // We use lodash's grapheme splitter to avoid breaking apart compound emojis
566
- if ( EMOJIBASE_REGEX . test ( split ( input , "" , 2 ) [ 0 ] ) ) {
565
+ if ( EMOJIBASE_REGEX . test ( getFirstGrapheme ( input ) ) ) {
567
566
return new EmojiPart ( ) ;
568
567
}
569
568
return new PlainPart ( ) ;
@@ -639,8 +638,8 @@ export class PartCreator {
639
638
const parts : ( PlainPart | EmojiPart ) [ ] = [ ] ;
640
639
let plainText = "" ;
641
640
642
- // We use lodash's grapheme splitter to avoid breaking apart compound emojis
643
- for ( const char of split ( text , "" ) ) {
641
+ const splitter = new GraphemeSplitter ( ) ;
642
+ for ( const char of splitter . iterateGraphemes ( text ) ) {
644
643
if ( EMOJIBASE_REGEX . test ( char ) ) {
645
644
if ( plainText ) {
646
645
parts . push ( this . plain ( plainText ) ) ;
0 commit comments