Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): replace the whole +: token when picking a reaction emoji (#1916)

Hampus9efd2b0a73a1
diff --git a/fluxer_app/src/features/lexical/composer/ComposerAutocompleteInsertion.ts b/fluxer_app/src/features/lexical/composer/ComposerAutocompleteInsertion.ts
index eb5f0758a..87d32653f 100644
--- a/fluxer_app/src/features/lexical/composer/ComposerAutocompleteInsertion.ts
+++ b/fluxer_app/src/features/lexical/composer/ComposerAutocompleteInsertion.ts
@@ -28,6 +28,10 @@ export function getComposerAutocompleteReplacementStart(
if (type === 'commandArg') {
return Math.max(0, textUpToCursor.length - (matchedArgument == null ? 0 : matchedArgument.length));
}
+ if (type === 'emojiReaction') {
+ const whole = match[0] == null ? '' : match[0];
+ return Math.max(0, (match.index == null ? 0 : match.index) + (whole.length - whole.trimStart().length));
+ }
return Math.max(0, (match.index == null ? 0 : match.index) + (matchedPrefix == null ? 0 : matchedPrefix.length));
}
diff --git a/fluxer_app/src/features/lexical/composer/composerTypeaheadTrigger.ts b/fluxer_app/src/features/lexical/composer/composerTypeaheadTrigger.ts
index dc3e5dd98..f81308df1 100644
--- a/fluxer_app/src/features/lexical/composer/composerTypeaheadTrigger.ts
+++ b/fluxer_app/src/features/lexical/composer/composerTypeaheadTrigger.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {getComposerAutocompleteReplacementStart} from '@app/features/lexical/composer/ComposerAutocompleteInsertion';
import {detectAutocompleteTrigger} from '@app/features/messaging/utils/SlashCommandUtils';
import type {MenuTextMatch} from '@lexical/react/LexicalTypeaheadMenuPlugin';
@@ -8,8 +9,7 @@ export function buildComposerMenuMatch(fullText: string, anchorText: string): Me
if (trigger == null) {
return null;
}
- const matchStart =
- (trigger.match.index == null ? 0 : trigger.match.index) + (trigger.match[1] == null ? 0 : trigger.match[1].length);
+ const matchStart = getComposerAutocompleteReplacementStart(fullText, trigger.type, trigger.match);
const tokenLength = fullText.length - matchStart;
const leadOffset = Math.max(0, anchorText.length - tokenLength);
return {