Accept non-Latin characters to suggest hash tag (#39696)

This commit is contained in:
zunda
2026-07-02 02:50:12 -10:00
committed by Claire
parent ed8fbafb56
commit dba4b37b8f
3 changed files with 36 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
import { textAtCursorMatchesToken } from './utils';
describe('textAtCursorMatchesToken', () => {
test.concurrent.for([
[
['#hashtag', 7, ['#']],
[1, '#hashtag'],
],
[
['#hash tag', 8, ['#']],
[1, '#hash tag'],
],
[
['#ハッシュタグ', 6, ['#']],
[1, '#ハッシュタグ'],
],
[
['#ハッシュ タグ', 7, ['#']],
[1, '#ハッシュ タグ'],
],
] as const)(
'textAtCursorMatchesToken(%s) is %o',
([input, expected], { expect }) => {
expect(
textAtCursorMatchesToken(input[0], input[1], Array.from(input[2])),
).toStrictEqual(expected);
},
);
});

View File

@@ -1,3 +1,5 @@
import { WORD } from '../../utils/hashtags';
export const textAtCursorMatchesToken = (
str: string,
caretPosition: number,
@@ -5,7 +7,10 @@ export const textAtCursorMatchesToken = (
) => {
let word: string;
const regex = new RegExp(`[${searchTokens.join('')}\\w]+(\\s[\\w]+)?$`);
const regex = new RegExp(
`[${searchTokens.join('')}${WORD}]+(\\s[${WORD}]+)?$`,
'iu',
);
const left = str.slice(0, caretPosition).search(regex);
const right = str.slice(caretPosition).search(/\s/);

View File

@@ -1,6 +1,6 @@
const HASHTAG_SEPARATORS = '_\\u00b7\\u200c';
const ALPHA = '\\p{L}\\p{M}';
const WORD = '\\p{L}\\p{M}\\p{N}\\p{Pc}';
export const WORD = '\\p{L}\\p{M}\\p{N}\\p{Pc}';
const buildHashtagPatternRegex = () => {
try {