Skip to content

Build your personal knowledge base with Trilium Notes

feat(options): stabilize shortcut row layout and add recording toast

Elian Dorand00b4b7aa0b6
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index ee932b5063..9a1323d566 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1734,6 +1734,7 @@
"record_shortcut": "Add a shortcut",
"remove_shortcut": "Remove this shortcut",
"press_keys": "Press keys…",
+ "recording_toast": "Press a key combination to assign it, or Esc to cancel.",
"make_global": "Make this a system-wide (global) shortcut",
"make_local": "Make this an in-app shortcut",
"global_shortcut": "System-wide (global) shortcut, only active on the desktop app"
diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.css b/apps/client/src/widgets/type_widgets/options/shortcuts.css
index d3646ca4dc..6b94817f19 100644
--- a/apps/client/src/widgets/type_widgets/options/shortcuts.css
+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.css
@@ -38,6 +38,14 @@
gap: 0.5em;
}
+ /* Fixed-width slot matching the .icon-action button, so the revert button never shifts the row. */
+ .shortcut-revert-slot {
+ flex: 0 0 auto;
+ display: flex;
+ justify-content: center;
+ width: 37px;
+ }
+
.shortcut-editor {
display: flex;
flex-wrap: wrap;
@@ -94,17 +102,10 @@
}
}
- /* Idle state reuses the standard .icon-action button styling; only the recording pill is custom. */
+ /* The recorder stays a fixed-size .icon-action button; recording is shown as an active highlight
+ (no size change) so toggling it never reflows the row. */
.shortcut-recorder.recording {
- display: inline-flex;
- align-items: center;
- height: 35px;
- padding-inline: 0.75em;
- border: 1px solid var(--link-color);
- border-radius: var(--button-border-radius);
- background: var(--button-background-color);
color: var(--link-color);
- white-space: nowrap;
- cursor: pointer;
+ border-color: var(--link-color);
}
}
diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
index 3078bce97e..4d46bf78c9 100644
--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
@@ -8,6 +8,7 @@ import { t } from "../../../services/i18n";
import options from "../../../services/options";
import server from "../../../services/server";
import { KEYCODES_WITH_NO_MODIFIER } from "../../../services/shortcuts";
+import toast from "../../../services/toast";
import { arrayEqual, isElectron, reloadFrontendApp } from "../../../services/utils";
import ActionButton from "../../react/ActionButton";
import Button from "../../react/Button";
@@ -185,13 +186,16 @@ function ShortcutRow({ action }: { action: ActionKeyboardShortcut }) {
>
<div class="shortcut-row-input">
<ShortcutEditor keyboardShortcut={action} />
- {isShortcutModified(action) &&
- <ActionButton
- icon="bx bx-reset"
- text={t("shortcuts.revert_to_default", { shortcuts: formatDefaultShortcuts(action) })}
- tooltipClass="tooltip-top"
- onClick={() => revertShortcut(action)}
- />}
+ {/* Always reserve the slot so the revert button appearing/disappearing never shifts the row. */}
+ <span class="shortcut-revert-slot">
+ {isShortcutModified(action) &&
+ <ActionButton
+ icon="bx bx-reset"
+ text={t("shortcuts.revert_to_default", { shortcuts: formatDefaultShortcuts(action) })}
+ tooltipClass="tooltip-top"
+ onClick={() => revertShortcut(action)}
+ />}
+ </span>
</div>
</OptionsRow>
);
@@ -253,6 +257,8 @@ function ShortcutEditor({ keyboardShortcut: action }: { keyboardShortcut: Action
);
}
+const RECORDING_TOAST_ID = "shortcut-recorder-recording";
+
function ShortcutRecorder({ onCapture }: { onCapture: (shortcut: string) => void }) {
const [ recording, setRecording ] = useState(false);
@@ -261,6 +267,12 @@ function ShortcutRecorder({ onCapture }: { onCapture: (shortcut: string) => void
return;
}
+ toast.showPersistent({
+ id: RECORDING_TOAST_ID,
+ icon: "bx bxs-keyboard",
+ message: t("shortcuts.recording_toast")
+ });
+
const onKeyDown = (e: KeyboardEvent) => {
// Swallow the combination so it never reaches the application's own shortcut handlers.
e.preventDefault();
@@ -282,21 +294,22 @@ function ShortcutRecorder({ onCapture }: { onCapture: (shortcut: string) => void
// Capture phase on window so we intercept the keystroke ahead of any other listener.
window.addEventListener("keydown", onKeyDown, true);
- return () => window.removeEventListener("keydown", onKeyDown, true);
+ return () => {
+ window.removeEventListener("keydown", onKeyDown, true);
+ toast.closePersistent(RECORDING_TOAST_ID);
+ };
}, [ recording, onCapture ]);
+ // Keep the button a fixed-size icon-action in both states so toggling recording never reflows
+ // the row; the recording state is conveyed through styling and the tooltip.
return (
<button
type="button"
- class={recording
- ? "shortcut-recorder recording"
- : "shortcut-recorder icon-action bx bx-plus"}
- title={recording ? undefined : t("shortcuts.record_shortcut")}
+ class={`shortcut-recorder icon-action bx bx-plus ${recording ? "recording" : ""}`}
+ title={recording ? t("shortcuts.press_keys") : t("shortcuts.record_shortcut")}
onClick={() => setRecording((value) => !value)}
onBlur={() => setRecording(false)}
- >
- {recording ? t("shortcuts.press_keys") : null}
- </button>
+ />
);
}