mirror of
https://github.com/zadam/trilium.git
synced 2025-12-12 02:14:25 +01:00
feat(ckeditor/watchdog): restore focus after crash
This commit is contained in:
parent
1bbf86fbeb
commit
2834af66e9
@ -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 dialog from "../../../services/dialog";
|
||||||
import toast from "../../../services/toast";
|
import toast from "../../../services/toast";
|
||||||
import utils, { hasTouchBar, isMobile } from "../../../services/utils";
|
import utils, { hasTouchBar, isMobile } from "../../../services/utils";
|
||||||
@ -214,6 +214,8 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
|
|||||||
addTextToEditor(text);
|
addTextToEditor(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onWatchdogStateChange = useWatchdogCrashHandling();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{note && !!templates && <CKEditorWithWatchdog
|
{note && !!templates && <CKEditorWithWatchdog
|
||||||
@ -275,20 +277,31 @@ function useTemplates() {
|
|||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onWatchdogStateChange(watchdog: EditorWatchdog) {
|
function useWatchdogCrashHandling() {
|
||||||
const currentState = watchdog.state;
|
const hasCrashed = useRef(false);
|
||||||
logInfo(`CKEditor state changed to ${currentState}`);
|
const onWatchdogStateChange = useCallback((watchdog: EditorWatchdog) => {
|
||||||
|
const currentState = watchdog.state;
|
||||||
|
logInfo(`CKEditor state changed to ${currentState}`);
|
||||||
|
|
||||||
if (!["crashed", "crashedPermanently"].includes(currentState)) {
|
if (currentState === "ready") {
|
||||||
return;
|
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") {
|
hasCrashed.current = true;
|
||||||
dialog.info(t("editable-text.keeps-crashing"));
|
logError(`CKEditor crash logs: ${JSON.stringify(watchdog.crashes, null, 4)}`);
|
||||||
watchdog.editor?.enableReadOnlyMode("crashed-editor");
|
|
||||||
}
|
if (currentState === "crashedPermanently") {
|
||||||
|
dialog.info(t("editable-text.keeps-crashing"));
|
||||||
|
watchdog.editor?.enableReadOnlyMode("crashed-editor");
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return onWatchdogStateChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onNotificationWarning(data, evt) {
|
function onNotificationWarning(data, evt) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user