mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +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);
|
||||
|
||||
for (const mention of sortedMentions) {
|
||||
const displayPattern = new RegExp(
|
||||
const mentionPatterns = sortedMentions.map((mention) => ({
|
||||
pattern: new RegExp(
|
||||
`@${escapeRegExp(mention.displayName)}(?=\\s|$|[.,!?;:])`,
|
||||
"g"
|
||||
);
|
||||
const dataFormat = `@[${mention.id}]`;
|
||||
result = result.replace(displayPattern, dataFormat);
|
||||
),
|
||||
dataFormat: `@[${mention.id}]`,
|
||||
}));
|
||||
|
||||
for (const { pattern, dataFormat } of mentionPatterns) {
|
||||
pattern.lastIndex = 0; // reset global regex state
|
||||
result = result.replace(pattern, dataFormat);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue