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);
|
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 [];
|
if (!$el[0]) return [];
|
||||||
|
|
||||||
const actions = await getActionsForScope(scope);
|
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 action of actions) {
|
||||||
for (const shortcut of action.effectiveShortcuts ?? []) {
|
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) {
|
if (binding) {
|
||||||
bindings.push(binding);
|
bindings.push(binding);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -760,18 +760,18 @@ export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => v
|
|||||||
}, [ callback, ref ]);
|
}, [ 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(() => {
|
useEffect(() => {
|
||||||
if (!parentComponent) return;
|
if (!parentComponent) return;
|
||||||
const $container = refToJQuerySelector(containerRef);
|
const $container = refToJQuerySelector(containerRef);
|
||||||
const bindingPromise = keyboard_actions.setupActionsForElement(scope, $container, parentComponent);
|
const bindingPromise = keyboard_actions.setupActionsForElement(scope, $container, parentComponent, ntxId);
|
||||||
return async () => {
|
return async () => {
|
||||||
const bindings = await bindingPromise;
|
const bindings = await bindingPromise;
|
||||||
for (const binding of bindings) {
|
for (const binding of bindings) {
|
||||||
removeIndividualBinding(binding);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -39,9 +39,9 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
|
|||||||
const watchdogRef = useRef<EditorWatchdog>(null);
|
const watchdogRef = useRef<EditorWatchdog>(null);
|
||||||
const [ uiLanguage ] = useTriliumOption("locale");
|
const [ uiLanguage ] = useTriliumOption("locale");
|
||||||
const [ editor, setEditor ] = useState<CKTextEditor>();
|
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, () => ({
|
useImperativeHandle(editorApi, () => ({
|
||||||
hasSelection() {
|
hasSelection() {
|
||||||
|
|||||||
@ -2,12 +2,11 @@ import { 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";
|
||||||
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 { TypeWidgetProps } from "../type_widget";
|
||||||
import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog";
|
import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog";
|
||||||
import "./EditableText.css";
|
import "./EditableText.css";
|
||||||
import { CKTextEditor, ClassicEditor, EditorWatchdog, TemplateDefinition } from "@triliumnext/ckeditor5";
|
import { CKTextEditor, EditorWatchdog, TemplateDefinition } from "@triliumnext/ckeditor5";
|
||||||
import Component from "../../../components/component";
|
|
||||||
import options from "../../../services/options";
|
import options from "../../../services/options";
|
||||||
import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./utils";
|
import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./utils";
|
||||||
import getTemplates, { updateTemplateCache } from "./snippets.js";
|
import getTemplates, { updateTemplateCache } from "./snippets.js";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user