From ec3c9a9ae55272e5014e7dc1c05d161c2f00dccd Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 16 Dec 2025 18:16:05 +0200 Subject: [PATCH] feat(layout): keyboard shortcut for formatting toolbar --- .../src/widgets/ribbon/FormattingToolbar.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx index 610063a3c..0225a74bc 100644 --- a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx +++ b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx @@ -49,6 +49,21 @@ export function FixedFormattingToolbar() { const renderState = useRenderState(noteContext, note); const [ toolbarToRender, setToolbarToRender ] = useState(); + // Keyboard shortcut. + const lastFocusedElement = useRef(null); + useTriliumEvent("toggleRibbonTabClassicEditor", () => { + if (!toolbarToRender) return; + if (!toolbarToRender.contains(document.activeElement)) { + // Focus to the fixed formatting toolbar. + lastFocusedElement.current = document.activeElement; + toolbarToRender.querySelector(".ck-toolbar__items button")?.focus(); + } else { + // Focus back to the last selection. + (lastFocusedElement.current as HTMLElement)?.focus(); + lastFocusedElement.current = null; + } + }); + // Populate the cache with the toolbar of every note context. useTriliumEvent("textEditorRefreshed", ({ ntxId: eventNtxId, editor }) => { if (!eventNtxId) return;