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;