From aa4992e71665f03be23c7bf14653eea2a4b89bd4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 23 Sep 2023 14:22:27 -0500 Subject: [PATCH] AutosuggestPlugin: update when suggestions updates --- .../compose/editor/plugins/autosuggest-plugin.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/features/compose/editor/plugins/autosuggest-plugin.tsx b/src/features/compose/editor/plugins/autosuggest-plugin.tsx index 6900d7a9e..74c638604 100644 --- a/src/features/compose/editor/plugins/autosuggest-plugin.tsx +++ b/src/features/compose/editor/plugins/autosuggest-plugin.tsx @@ -293,13 +293,11 @@ const AutosuggestPlugin = ({ const handleSelectSuggestion: React.MouseEventHandler = (e) => { e.preventDefault(); - - const index = e.currentTarget.getAttribute('data-index'); - + const index = Number(e.currentTarget.getAttribute('data-index')); return onSelectSuggestion(index); }; - const onSelectSuggestion = (index: any) => { + const onSelectSuggestion = (index: number) => { const suggestion = suggestions.get(index) as AutoSuggestion; editor.update(() => { @@ -349,15 +347,12 @@ const AutosuggestPlugin = ({ if (['mention', 'hashtag'].includes(node.getType())) { const matchingString = node.getTextContent(); - return { leadOffset: 0, matchingString }; } if (node.getType() === 'text') { const [leadOffset, matchingString] = textAtCursorMatchesToken(node.getTextContent(), (state._selection as RangeSelection)?.anchor?.offset, [':']); - if (!leadOffset || !matchingString) return null; - return { leadOffset, matchingString }; } @@ -536,7 +531,7 @@ const AutosuggestPlugin = ({ COMMAND_PRIORITY_LOW, ), ); - }, [editor, selectedSuggestion, resolution]); + }, [editor, suggestions, selectedSuggestion, resolution]); return resolution === null || editor === null ? null : (