mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-28 02:23:53 +02:00
fix(comment-composer): hoist RegExp out of loop to satisfy js-hoist-regexp rule
This commit is contained in:
parent
ccd0e3b807
commit
f1be2652a0
1 changed files with 9 additions and 5 deletions
|
|
@ -15,13 +15,17 @@ function convertDisplayToData(displayContent: string, mentions: InsertedMention[
|
||||||
|
|
||||||
const sortedMentions = [...mentions].sort((a, b) => b.displayName.length - a.displayName.length);
|
const sortedMentions = [...mentions].sort((a, b) => b.displayName.length - a.displayName.length);
|
||||||
|
|
||||||
for (const mention of sortedMentions) {
|
const mentionPatterns = sortedMentions.map((mention) => ({
|
||||||
const displayPattern = new RegExp(
|
pattern: new RegExp(
|
||||||
`@${escapeRegExp(mention.displayName)}(?=\\s|$|[.,!?;:])`,
|
`@${escapeRegExp(mention.displayName)}(?=\\s|$|[.,!?;:])`,
|
||||||
"g"
|
"g"
|
||||||
);
|
),
|
||||||
const dataFormat = `@[${mention.id}]`;
|
dataFormat: `@[${mention.id}]`,
|
||||||
result = result.replace(displayPattern, dataFormat);
|
}));
|
||||||
|
|
||||||
|
for (const { pattern, dataFormat } of mentionPatterns) {
|
||||||
|
pattern.lastIndex = 0; // reset global regex state
|
||||||
|
result = result.replace(pattern, dataFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue