fix(app): refocus the editor before text context menu actions (#3292)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-08 17:37:40 +02:00
1 parent 0906a85d6f
commit c3d790f664
2 files changed
+13 -7

No files matched your search

@@ -140,12 +140,6 @@ export const TextareaContextMenu = observer(
} }
targetElement.focus({preventScroll: true}); targetElement.focus({preventScroll: true});
}; };
const handleReplaceMisspelling = async (suggestion: string) => {
if (electronAPI?.spellcheckReplaceMisspelling) {
await electronAPI.spellcheckReplaceMisspelling(suggestion);
}
onClose();
};
const handleAddToDictionary = async () => { const handleAddToDictionary = async () => {
if (!misspelledWord) return; if (!misspelledWord) return;
Spellcheck.addPersonalWord(misspelledWord); Spellcheck.addPersonalWord(misspelledWord);
@@ -167,6 +161,11 @@ export const TextareaContextMenu = observer(
requestAnimationFrame(action); requestAnimationFrame(action);
}); });
}; };
const handleReplaceMisspelling = (suggestion: string) => {
runAfterClose(() => {
void electronAPI?.spellcheckReplaceMisspelling?.(suggestion);
});
};
const execCommand = (command: string) => { const execCommand = (command: string) => {
runAfterClose(() => { runAfterClose(() => {
document.execCommand(command); document.execCommand(command);
@@ -87,6 +87,13 @@ const createSyntheticEvent = (
relatedTarget: null, relatedTarget: null,
} satisfies React.MouseEvent<HTMLElement>; } 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 => { const getEditableTarget = (node: Element | null): HTMLElement | null => {
if (!node) return null; if (!node) return null;
if (node instanceof HTMLTextAreaElement) { if (node instanceof HTMLTextAreaElement) {
@@ -99,7 +106,7 @@ const getEditableTarget = (node: Element | null): HTMLElement | null => {
} }
} }
if ((node as HTMLElement).isContentEditable) { if ((node as HTMLElement).isContentEditable) {
return node as HTMLElement; return getEditingHost(node as HTMLElement);
} }
const textarea = node.closest('textarea') as HTMLTextAreaElement | null; const textarea = node.closest('textarea') as HTMLTextAreaElement | null;
if (textarea) { if (textarea) {