Fix autosuggestions overstaying their welcome in languages that don't use spaces (#40217)

This commit is contained in:
Eugen Rochko
2026-08-20 08:14:50 +00:00
committed by GitHub
parent 2fa679f4a4
commit 8d8b9c84a4
3 changed files with 39 additions and 3 deletions

View File

@@ -6,6 +6,14 @@ describe('textAtCursorMatchesToken', () => {
['#hashtag', 7, ['#']],
[1, '#hashtag'],
],
[
['@alice', 6, ['@']],
[1, '@alice'],
],
[
['alice', 6, ['']],
[1, 'alice'],
],
[
['#hash tag', 8, ['#']],
[1, '#hash tag'],
@@ -24,7 +32,35 @@ describe('textAtCursorMatchesToken', () => {
],
[
['#ハッシュ タグ', 7, ['#']],
[1, '#ハッシュ タグ'],
[null, null],
],
[
['@alice reply', 12, ['@']],
[1, '@alice reply'],
],
[
['@alice 这是我输入的回复内容', 17, ['@']],
[null, null],
],
[
['@alice これは本文', 12, ['@']],
[null, null],
],
[
['@alice 이것은답변입니다', 15, ['@']],
[null, null],
],
[
['@alice これは本文', 12, ['@']],
[null, null],
],
[
['@алиса', 6, ['@']],
[1, '@алиса'],
],
[
['@алиса пример', 13, ['@']],
[1, '@алиса пример'],
],
] as const)(
'textAtCursorMatchesToken(%s) is %o',

View File

@@ -8,7 +8,7 @@ export const textAtCursorMatchesToken = (
let word: string;
const regex = new RegExp(
`[${searchTokens.join('')}${WORD}+-]+(\\s[${WORD}]+)?$`,
`[${searchTokens.join('')}${WORD}+-]+(\\s[\\p{Script=Latin}\\p{Script=Cyrillic}\\p{M}]+)?$`,
'iu',
);
const left = str.slice(0, caretPosition).search(regex);

View File

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