From c434e0dda3ba29c995298d34945c46d1be0d2818 Mon Sep 17 00:00:00 2001 From: wjaaaaaaat <04amid.foyer@icloud.com> Date: Tue, 11 Aug 2026 00:23:15 -0400 Subject: [PATCH] fix: emoji autocompletion overwriting preceding element (#3064) * fix getPrevWorldRange to exclude empty text children this prevents the range from encroaching on the node of elements like emojis and pings to prevent them from being overwritten * fix typo of "word" as "world" * trigger pr checks --- src/app/components/editor/utils.ts | 8 ++++---- src/app/features/room/RoomInput.tsx | 4 ++-- src/app/features/room/message/MessageEditor.tsx | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/components/editor/utils.ts b/src/app/components/editor/utils.ts index 90c549c84..f63c5ac94 100644 --- a/src/app/components/editor/utils.ts +++ b/src/app/components/editor/utils.ts @@ -241,15 +241,15 @@ export const getPointUntilChar = ( return targetPoint; }; -export const getPrevWorldRange = (editor: Editor): BaseRange | undefined => { +export const getPrevWordRange = (editor: Editor): BaseRange | undefined => { const { selection } = editor; if (!selection || !Range.isCollapsed(selection)) return undefined; const [cursorPoint] = Range.edges(selection); - const worldStartPoint = getPointUntilChar(editor, cursorPoint, { + const wordStartPoint = getPointUntilChar(editor, cursorPoint, { reverse: true, - match: (char) => char === ' ', + match: (char) => char === ' ' || char === '', }); - return worldStartPoint && Editor.range(editor, worldStartPoint, cursorPoint); + return wordStartPoint && Editor.range(editor, wordStartPoint, cursorPoint); }; export const isEmptyEditor = (editor: Editor): boolean => { diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index f88ccf938..466754286 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -39,7 +39,7 @@ import { AutocompletePrefix, AutocompleteQuery, getAutocompleteQuery, - getPrevWorldRange, + getPrevWordRange, resetEditor, RoomMentionAutocomplete, UserMentionAutocomplete, @@ -411,7 +411,7 @@ export const RoomInput = forwardRef( sendTypingStatus(!isEmptyEditor(editor)); } - const prevWordRange = getPrevWorldRange(editor); + const prevWordRange = getPrevWordRange(editor); const query = prevWordRange ? getAutocompleteQuery(editor, prevWordRange, AUTOCOMPLETE_PREFIXES) : undefined; diff --git a/src/app/features/room/message/MessageEditor.tsx b/src/app/features/room/message/MessageEditor.tsx index 9a7567aac..2d7f20978 100644 --- a/src/app/features/room/message/MessageEditor.tsx +++ b/src/app/features/room/message/MessageEditor.tsx @@ -35,7 +35,7 @@ import { createEmoticonElement, customHtmlEqualsPlainText, getAutocompleteQuery, - getPrevWorldRange, + getPrevWordRange, htmlToEditorInput, moveCursor, plainToEditorInput, @@ -187,7 +187,7 @@ export const MessageEditor = as<'div', MessageEditorProps>( return; } - const prevWordRange = getPrevWorldRange(editor); + const prevWordRange = getPrevWordRange(editor); const query = prevWordRange ? getAutocompleteQuery(editor, prevWordRange, AUTOCOMPLETE_PREFIXES) : undefined;