A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): refocus the editor before text context menu actions (#3292)
Hampusc3d790f66496
diff --git a/fluxer_app/src/features/channel/components/textarea/TextareaContextMenu.tsx b/fluxer_app/src/features/channel/components/textarea/TextareaContextMenu.tsxindex 0236d88ac..6c0abbe91 100644--- a/fluxer_app/src/features/channel/components/textarea/TextareaContextMenu.tsx+++ b/fluxer_app/src/features/channel/components/textarea/TextareaContextMenu.tsx@@ -140,12 +140,6 @@ export const TextareaContextMenu = observer(}targetElement.focus({preventScroll: true});};- const handleReplaceMisspelling = async (suggestion: string) => {- if (electronAPI?.spellcheckReplaceMisspelling) {- await electronAPI.spellcheckReplaceMisspelling(suggestion);- }- onClose();- };const handleAddToDictionary = async () => {if (!misspelledWord) return;Spellcheck.addPersonalWord(misspelledWord);@@ -167,6 +161,11 @@ export const TextareaContextMenu = observer(requestAnimationFrame(action);});};+ const handleReplaceMisspelling = (suggestion: string) => {+ runAfterClose(() => {+ void electronAPI?.spellcheckReplaceMisspelling?.(suggestion);+ });+ };const execCommand = (command: string) => {runAfterClose(() => {document.execCommand(command);diff --git a/fluxer_app/src/features/ui/hooks/useTextInputContextMenu.tsx b/fluxer_app/src/features/ui/hooks/useTextInputContextMenu.tsxindex 4244c5dbb..7a419b61c 100644--- a/fluxer_app/src/features/ui/hooks/useTextInputContextMenu.tsx+++ b/fluxer_app/src/features/ui/hooks/useTextInputContextMenu.tsx@@ -87,6 +87,13 @@ const createSyntheticEvent = (relatedTarget: null,} satisfies React.MouseEvent<HTMLElement>;};+const getEditingHost = (element: HTMLElement): HTMLElement => {+ let host = element;+ while (host.parentElement?.isContentEditable) {+ host = host.parentElement;+ }+ return host;+};const getEditableTarget = (node: Element | null): HTMLElement | null => {if (!node) return null;if (node instanceof HTMLTextAreaElement) {@@ -99,7 +106,7 @@ const getEditableTarget = (node: Element | null): HTMLElement | null => {}}if ((node as HTMLElement).isContentEditable) {- return node as HTMLElement;+ return getEditingHost(node as HTMLElement);}const textarea = node.closest('textarea') as HTMLTextAreaElement | null;if (textarea) {