Skip to content

Build your personal knowledge base with Trilium Notes

fix(text): insert link sometimes occurs in the wrong tab

Elian Doran398329a21928
diff --git a/apps/client/src/services/keyboard_actions.ts b/apps/client/src/services/keyboard_actions.ts
index 9fce5ad356..1ada409ecd 100644
--- a/apps/client/src/services/keyboard_actions.ts
+++ b/apps/client/src/services/keyboard_actions.ts
@@ -29,6 +29,8 @@ async function getActionsForScope(scope: string) {
}
async function setupActionsForElement(scope: string, $el: JQuery<HTMLElement>, component: Component) {
+ if (!$el[0]) return;
+
const actions = await getActionsForScope(scope);
const bindings: ShortcutBinding[] = [];
diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
index eaf85a08f5..b7346dd9a1 100644
--- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
+++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
@@ -1,7 +1,7 @@
import { HTMLProps, RefObject, useEffect, useImperativeHandle, useRef, useState } from "preact/compat";
import { PopupEditor, ClassicEditor, EditorWatchdog, type WatchdogConfig, CKTextEditor, TemplateDefinition } from "@triliumnext/ckeditor5";
import { buildConfig, BuildEditorOptions } from "./config";
-import { useLegacyImperativeHandlers, useSyncedRef } from "../../react/hooks";
+import { useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteContext, useSyncedRef } from "../../react/hooks";
import link from "../../../services/link";
import froca from "../../../services/froca";
@@ -38,6 +38,9 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
const containerRef = useSyncedRef<HTMLDivElement>(externalContainerRef, null);
const watchdogRef = useRef<EditorWatchdog>(null);
const [ editor, setEditor ] = useState<CKTextEditor>();
+ const { parentComponent } = useNoteContext();
+
+ useKeyboardShortcuts("text-detail", containerRef, parentComponent);
useImperativeHandle(editorApi, () => ({
hasSelection() {
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index f39ea3992e..aa6e0b589e 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -196,7 +196,6 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
});
}
- useKeyboardShortcuts("text-detail", containerRef, parentComponent);
useTriliumEvent("insertDateTimeToText", ({ ntxId: eventNtxId }) => {
if (eventNtxId !== ntxId) return;
const date = new Date();