Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
style/shortcut hints: improve the appearance of the panel
Adorian Doranfc5362839e77
diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.css b/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.cssindex 54631ae6c4..f972b6690a 100644--- a/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.css+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.css@@ -2,25 +2,9 @@gap: 5px;white-space: nowrap;+ /* Keycap style comes from the shared `.tn-shortcut-hints-kbd` rule. */+.shortcut-hint-button-key {font-size: 0.85em;}-- /* Match the CKEditor content keycap style (see `.ck-content kbd`). */- kbd {- display: inline-block;- border: 1px solid var(--help-kbd-shortcut-border);- border-radius: 5px;- padding: 0 5px;- background: var(--help-kbd-shortcut-background);- box-shadow:- 0 2px 0 var(--help-kbd-shortcut-border),- inset 0 -1px 0 var(--help-kbd-shortcut-border);- color: var(--help-kbd-shortcut-color);- font-family: var(--main-font-family);- font-size: 0.7em;- font-weight: normal;- line-height: 1.4;- letter-spacing: 0.5pt;- }}diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.tsx b/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.tsxindex ba067a19a3..dda52eb220 100644--- a/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.tsx+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.tsx@@ -1,3 +1,4 @@+import "./shortcut_hints_kbd.css";import "./shortcut_hint_button.css";import clsx from "clsx";@@ -40,7 +41,7 @@ export default function ShortcutHintButton({ className }: { className?: string }<buttonref={buttonRef}type="button"- className="tn-overlay-text-button shortcut-hint-button"+ className="tn-overlay-text-button shortcut-hint-button tn-shortcut-hints-kbd"aria-label={t("shortcut_hints.show_button")}onClick={onClick}>diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_kbd.css b/apps/client/src/widgets/shortcut_hints/shortcut_hints_kbd.cssnew file mode 100644index 0000000000..aac6a081fa--- /dev/null+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_kbd.css@@ -0,0 +1,17 @@+/* Keycap style matching CKEditor content (`.ck-content kbd`); shared by the hints button and pane. */+.tn-shortcut-hints-kbd kbd {+ display: inline-block;+ border: 1px solid var(--help-kbd-shortcut-border);+ border-radius: 5px;+ padding: 0 5px;+ background: var(--help-kbd-shortcut-background);+ box-shadow:+ 0 2px 0 var(--help-kbd-shortcut-border),+ inset 0 -1px 0 var(--help-kbd-shortcut-border);+ color: var(--help-kbd-shortcut-color);+ font-family: var(--main-font-family);+ font-size: 0.7em;+ font-weight: normal;+ line-height: 1.4;+ letter-spacing: 0.5pt;+}diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.cssindex 39a07a33e8..8df9c8edb3 100644--- a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css@@ -3,9 +3,11 @@right: 1rem;bottom: 1rem;z-index: 1080;- max-width: 340px;+ /* Grow to fit the widest shortcut row (so keys never wrap), capped to the viewport. */+ width: max-content;+ max-width: min(90vw, 640px);max-height: 60vh;- overflow-y: auto;+ overflow: auto;padding: 0.75rem 1rem;background-color: var(--main-background-color);border: 1px solid var(--main-border-color);@@ -17,12 +19,6 @@&:not(:last-child) {margin-bottom: 0.75rem;}-- ul {- margin: 0;- padding: 0;- list-style: none;- }}.shortcut-hints-section-title {@@ -30,20 +26,33 @@margin-bottom: 0.25rem;}- .shortcut-hint {- display: flex;- gap: 0.75rem;+ /* Borderless two-column table: action label (max-content) then shortcut keys (fills the rest). */+ .shortcut-hints-list {+ display: grid;+ grid-template-columns: max-content 1fr;+ column-gap: 1rem;+ row-gap: 0.25rem;align-items: baseline;- padding: 0.15rem 0;- }+ margin: 0;++ dt,+ dd {+ margin: 0;+ }- .shortcut-hint-keys {- flex: 0 0 auto;- white-space: nowrap;+ /* `dt` is bold by default (Bootstrap reboot); action names should read as normal text. */+ dt {+ font-weight: normal;+ }++ dd {+ white-space: nowrap;+ }}- .shortcut-hint-description {- flex: 1 1 auto;- color: var(--muted-text-color);+ /* Separate alternative shortcuts for the same action: "<keys>, <keys>". */+ .shortcut-hint-alt:not(:last-child)::after {+ content: ",";+ margin-inline-end: 8px;}}diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsxindex fe571c7117..5e624e9571 100644--- a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx@@ -1,6 +1,6 @@+import "./shortcut_hints_kbd.css";import "./shortcut_hints_panel.css";-import { Fragment } from "preact";import { createPortal } from "preact/compat";import { useCallback, useEffect, useRef, useState } from "preact/hooks";@@ -8,7 +8,6 @@ import { t } from "../../services/i18n.js";import keyboard_actions from "../../services/keyboard_actions.js";import type { ShortcutHint, ShortcutHintSection } from "../../services/shortcut_hints.js";import { useTriliumEvent } from "../react/hooks.js";-import { joinElements } from "../react/react_utils.js";import { renderShortcutKbds } from "../react/shortcut_kbd.js";/** How long the panel stays up when left untouched. Paused while hovered; other signals dismiss it sooner. */@@ -89,7 +88,7 @@ export default function ShortcutHintsPanel() {// Portal to <body> so no transformed / contained / overflow-clipped ancestor breaks the fixed// positioning or hides it behind content.return createPortal(- <div ref={panelRef} className="shortcut-hints-panel" style={style} onMouseEnter={clearTimer} onMouseLeave={startTimer}>+ <div ref={panelRef} className="shortcut-hints-panel tn-shortcut-hints-kbd" style={style} onMouseEnter={clearTimer} onMouseLeave={startTimer}><ShortcutHintsSections sections={state.sections} /></div>,document.body@@ -102,9 +101,9 @@ export function ShortcutHintsSections({ sections }: { sections: ShortcutHintSect{sections.map((section, i) => (<div className="shortcut-hints-section" key={i}>{section.titleKey && <div className="shortcut-hints-section-title">{t(section.titleKey)}</div>}- <ul>+ <dl className="shortcut-hints-list">{section.hints.map((hint, j) => <HintRow hint={hint} key={j} />)}- </ul>+ </dl></div>))}</>@@ -129,12 +128,16 @@ function HintRow({ hint }: { hint: ShortcutHint }) {const description = hint.labelKey ? t(hint.labelKey) : friendlyName ?? "";+ // `dt`/`dd` are direct children of the section's `dl`, so they align as the two grid columns:+ // action label (left) then shortcut keys (right).return (- <li className="shortcut-hint">- <span className="shortcut-hint-keys">- {joinElements(shortcuts.map((shortcut, i) => <Fragment key={i}>{renderShortcutKbds(shortcut)}</Fragment>), ", ")}- </span>- <span className="shortcut-hint-description">{description}</span>- </li>+ <>+ <dt className="shortcut-hint-description">{description}</dt>+ <dd className="shortcut-hint-keys">+ {shortcuts.map((shortcut, i) => (+ <span className="shortcut-hint-alt" key={i}>{renderShortcutKbds(shortcut)}</span>+ ))}+ </dd>+ </>);}