[Glitch] Accept non-Latin characters to suggest hash tag
Port 72085f7d5288692f85e411916d3f0f18a3603574 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
eda507e673
commit
449aa77337
@ -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);
|
||||
},
|
||||
);
|
||||
});
|
||||
@ -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/);
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user