Switch from graphemer to Intl.Segmenter (#12697)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
95c8aa3d18
commit
86a95cfff7
5 changed files with 15 additions and 19 deletions
|
@ -21,7 +21,6 @@ limitations under the License.
|
|||
* @param text the plaintext to put in the user's clipboard
|
||||
*/
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import GraphemeSplitter from "graphemer";
|
||||
|
||||
export async function copyPlaintext(text: string): Promise<boolean> {
|
||||
try {
|
||||
|
@ -85,6 +84,8 @@ export function getSelectedText(): string {
|
|||
return window.getSelection()!.toString();
|
||||
}
|
||||
|
||||
export const graphemeSegmenter = new Intl.Segmenter();
|
||||
|
||||
/**
|
||||
* Returns the first grapheme in the given string,
|
||||
* especially useful for strings containing emoji, will not break compound emoji up.
|
||||
|
@ -92,7 +93,6 @@ export function getSelectedText(): string {
|
|||
* @returns the first grapheme or an empty string if given an empty string
|
||||
*/
|
||||
export function getFirstGrapheme(str: string): string {
|
||||
const splitter = new GraphemeSplitter();
|
||||
const result = splitter.iterateGraphemes(str).next();
|
||||
return result.done ? "" : result.value;
|
||||
const result = graphemeSegmenter.segment(str)[Symbol.iterator]().next();
|
||||
return result.done ? "" : result.value.segment;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue