mirror of
https://github.com/zadam/trilium.git
synced 2025-11-26 02:24:23 +01:00
fix(quick_edit): keyboard shortcuts triggering on wrong editor
This commit is contained in:
parent
af62526b92
commit
435b856b72
@ -28,7 +28,7 @@ async function getActionsForScope(scope: string) {
|
||||
return actions.filter((action) => action.scope === scope);
|
||||
}
|
||||
|
||||
async function setupActionsForElement(scope: string, $el: JQuery<HTMLElement>, component: Component) {
|
||||
async function setupActionsForElement(scope: string, $el: JQuery<HTMLElement>, component: Component, ntxId: string | null | undefined) {
|
||||
if (!$el[0]) return [];
|
||||
|
||||
const actions = await getActionsForScope(scope);
|
||||
@ -36,7 +36,9 @@ async function setupActionsForElement(scope: string, $el: JQuery<HTMLElement>, c
|
||||
|
||||
for (const action of actions) {
|
||||
for (const shortcut of action.effectiveShortcuts ?? []) {
|
||||
const binding = shortcutService.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName, { ntxId: appContext.tabManager.activeNtxId }));
|
||||
const binding = shortcutService.bindElShortcut($el, shortcut, () => {
|
||||
component.triggerCommand(action.actionName, { ntxId });
|
||||
});
|
||||
if (binding) {
|
||||
bindings.push(binding);
|
||||
}
|
||||
|
||||
@ -760,18 +760,18 @@ export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => v
|
||||
}, [ callback, ref ]);
|
||||
}
|
||||
|
||||
export function useKeyboardShortcuts(scope: "code-detail" | "text-detail", containerRef: RefObject<HTMLElement>, parentComponent: Component | undefined) {
|
||||
export function useKeyboardShortcuts(scope: "code-detail" | "text-detail", containerRef: RefObject<HTMLElement>, parentComponent: Component | undefined, ntxId: string | null | undefined) {
|
||||
useEffect(() => {
|
||||
if (!parentComponent) return;
|
||||
const $container = refToJQuerySelector(containerRef);
|
||||
const bindingPromise = keyboard_actions.setupActionsForElement(scope, $container, parentComponent);
|
||||
const bindingPromise = keyboard_actions.setupActionsForElement(scope, $container, parentComponent, ntxId);
|
||||
return async () => {
|
||||
const bindings = await bindingPromise;
|
||||
for (const binding of bindings) {
|
||||
removeIndividualBinding(binding);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
}, [ scope, containerRef, parentComponent, ntxId ]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -100,7 +100,7 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC
|
||||
}
|
||||
});
|
||||
|
||||
useKeyboardShortcuts("code-detail", containerRef, parentComponent);
|
||||
useKeyboardShortcuts("code-detail", containerRef, parentComponent, ntxId);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@ -39,9 +39,9 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
|
||||
const watchdogRef = useRef<EditorWatchdog>(null);
|
||||
const [ uiLanguage ] = useTriliumOption("locale");
|
||||
const [ editor, setEditor ] = useState<CKTextEditor>();
|
||||
const { parentComponent } = useNoteContext();
|
||||
const { parentComponent, ntxId } = useNoteContext();
|
||||
|
||||
useKeyboardShortcuts("text-detail", containerRef, parentComponent);
|
||||
useKeyboardShortcuts("text-detail", containerRef, parentComponent, ntxId);
|
||||
|
||||
useImperativeHandle(editorApi, () => ({
|
||||
hasSelection() {
|
||||
|
||||
@ -2,12 +2,11 @@ import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import dialog from "../../../services/dialog";
|
||||
import toast from "../../../services/toast";
|
||||
import utils, { hasTouchBar, isMobile } from "../../../services/utils";
|
||||
import { useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteLabel, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
|
||||
import { useEditorSpacedUpdate, useLegacyImperativeHandlers, useNoteLabel, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
|
||||
import { TypeWidgetProps } from "../type_widget";
|
||||
import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog";
|
||||
import "./EditableText.css";
|
||||
import { CKTextEditor, ClassicEditor, EditorWatchdog, TemplateDefinition } from "@triliumnext/ckeditor5";
|
||||
import Component from "../../../components/component";
|
||||
import { CKTextEditor, EditorWatchdog, TemplateDefinition } from "@triliumnext/ckeditor5";
|
||||
import options from "../../../services/options";
|
||||
import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./utils";
|
||||
import getTemplates, { updateTemplateCache } from "./snippets.js";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user