mirror of
https://github.com/mastodon/mastodon.git
synced 2026-08-20 00:56:12 -05:00
Accept non-Latin characters to suggest hash tag (#39696)
This commit is contained in:
29
app/javascript/mastodon/components/autosuggest/utils.test.ts
Normal file
29
app/javascript/mastodon/components/autosuggest/utils.test.ts
Normal 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);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user