Skip to content

Build your personal knowledge base with Trilium Notes

feat(options): reveal shortcut add button on hover, reserve revert slot

Elian Doran0a77d299d50a
diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.css b/apps/client/src/widgets/type_widgets/options/shortcuts.css
index 264280ceb2..e2d7b3704b 100644
--- a/apps/client/src/widgets/type_widgets/options/shortcuts.css
+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.css
@@ -71,6 +71,16 @@
gap: 0.4em;
}
+ /* Reserve the revert button's slot (matching its .icon-action width) so the add button to its
+ right never shifts as a row's modified state toggles, while only mounting the button when
+ there's something to revert. */
+ .shortcut-revert-slot {
+ flex: 0 0 auto;
+ display: flex;
+ justify-content: center;
+ width: 37px;
+ }
+
.shortcut-chip {
display: inline-flex;
align-items: center;
@@ -84,26 +94,6 @@
box-shadow: inset 0 0 0 1px var(--icon-button-danger-color, #d9534f);
}
- /* Revert chip: previews the default the row reverts to. A plain gray chip; the whole chip is the
- button, with muted text to keep it quieter than the real (active) shortcut chips. */
- .shortcut-chip.shortcut-chip-revert {
- padding: 0.1em 0.5em;
- border: none;
- background: var(--input-background-color);
- color: var(--muted-text-color);
- cursor: pointer;
- transition: background 0.15s ease, color 0.15s ease;
- }
-
- .shortcut-chip.shortcut-chip-revert:hover {
- color: var(--main-text-color);
- background: var(--hover-item-background-color);
- }
-
- .shortcut-chip.shortcut-chip-revert kbd {
- color: inherit;
- }
-
.shortcut-chip-conflict {
color: var(--icon-button-danger-color, #d9534f);
}
@@ -155,6 +145,24 @@
border-color: var(--link-color);
}
+ /* Desktop: keep idle rows uncluttered by revealing the add button only on row hover (or while
+ it is focused / recording). Fade rather than display:none so the row never reflows. Mobile has
+ no hover, so the button stays visible there (see the body.mobile block below). */
+ body.desktop & {
+ .shortcut-recorder {
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 0.15s ease;
+ }
+
+ .option-row:hover .shortcut-recorder,
+ .shortcut-recorder:focus,
+ .shortcut-recorder.recording {
+ opacity: 1;
+ pointer-events: auto;
+ }
+ }
+
/* On mobile, stack each row so the shortcut editor sits underneath the action label.
OptionsRow keeps these rows inline because they contain .icon-action buttons. */
body.mobile & {
diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
index 32f49ca36c..92ff073eef 100644
--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
@@ -444,29 +444,22 @@ function ShortcutEditor({ keyboardShortcut: action, conflicts }: { keyboardShort
);
})}
- {isShortcutModified(action) && <RevertChip action={action} />}
+ {/* Reserve the slot so the add button never shifts when a row's modified state toggles,
+ but only mount the revert button when there's actually something to revert. */}
+ <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>
<ShortcutRecorder onCapture={addShortcut} />
</div>
);
}
-/**
- * Revert affordance styled like a shortcut chip: instead of an opaque reset icon, it previews the
- * default combination the row will return to, so the user sees the target before clicking.
- */
-function RevertChip({ action }: { action: ActionKeyboardShortcut }) {
- return (
- <TooltipButton
- className="shortcut-chip shortcut-chip-revert"
- title={t("shortcuts.revert_to_default", { shortcuts: formatDefaultShortcuts(action) })}
- onClick={() => revertShortcut(action)}
- >
- <span class="bx bx-reset" />
- <kbd>{formatDefaultShortcuts(action)}</kbd>
- </TooltipButton>
- );
-}
-
const RECORDING_TOAST_ID = "shortcut-recorder-recording";
function ShortcutRecorder({ onCapture }: { onCapture: (shortcut: string) => void }) {