From 2834af66e928d74c9ef8b594458ebb5bdc3f2b36 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 7 Dec 2025 19:36:46 +0200 Subject: [PATCH] feat(ckeditor/watchdog): restore focus after crash --- .../type_widgets/text/EditableText.tsx | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx index e3ba69c04..efc3f7d20 100644 --- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx +++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "preact/hooks"; +import { useCallback, useEffect, useRef, useState } from "preact/hooks"; import dialog from "../../../services/dialog"; import toast from "../../../services/toast"; import utils, { hasTouchBar, isMobile } from "../../../services/utils"; @@ -214,6 +214,8 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext addTextToEditor(text); }); + const onWatchdogStateChange = useWatchdogCrashHandling(); + return ( <> {note && !!templates && { + const currentState = watchdog.state; + logInfo(`CKEditor state changed to ${currentState}`); - if (!["crashed", "crashedPermanently"].includes(currentState)) { - return; - } + if (currentState === "ready") { + hasCrashed.current = false; + watchdog.editor?.focus(); + } - logError(`CKEditor crash logs: ${JSON.stringify(watchdog.crashes, null, 4)}`); + if (!["crashed", "crashedPermanently"].includes(currentState)) { + return; + } - if (currentState === "crashedPermanently") { - dialog.info(t("editable-text.keeps-crashing")); - watchdog.editor?.enableReadOnlyMode("crashed-editor"); - } + hasCrashed.current = true; + logError(`CKEditor crash logs: ${JSON.stringify(watchdog.crashes, null, 4)}`); + + if (currentState === "crashedPermanently") { + dialog.info(t("editable-text.keeps-crashing")); + watchdog.editor?.enableReadOnlyMode("crashed-editor"); + } + }, []); + + return onWatchdogStateChange; } function onNotificationWarning(data, evt) {