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
feat(options): render shortcuts as cards grouped by section
Elian Doran2c6033381152
diff --git a/apps/client/src/stylesheets/theme-next/pages.css b/apps/client/src/stylesheets/theme-next/pages.cssindex 36c4226ce3..5a9be81e74 100644--- a/apps/client/src/stylesheets/theme-next/pages.css+++ b/apps/client/src/stylesheets/theme-next/pages.css@@ -159,11 +159,6 @@visibility: hidden;}-/* Create a gap at the top of the option pages */-.note-detail-content-widget-content.options>*:first-child {- margin-top: var(--options-first-item-top-margin, 1em);-}-/* Create a gap at the bottom of option pages */.note-detail-content-widget-content.options::after {display: block;@@ -300,38 +295,13 @@ body.desktop .options-section:not(.tn-no-card) {/* Shortcuts */.note-detail-content-widget-content:has(.shortcuts-options-section) {- /* Allow the card to extend on the full width of the parent */+ /* Allow the cards to extend on the full width of the parent */--options-card-max-width: 100%;- /* Remove top padding for the options page */- --options-title-offset: 0px;- --options-title-font-size: 0px;-/* Remove the top margin of the first item */--options-first-item-top-margin: 0;}-.shortcuts-options-section h4 {- display: none;-}--/* Group heading */-.shortcuts-options-section .separator {- padding-top: 2em;- padding-bottom: 1em;- background: transparent !important;- font-weight: 500;-}--/* Simulates the underline for group headings */-.shortcuts-options-section .separator::after {- content: "";- display: block;- width: 100%;- height: 2px;- background: currentColor;-}-/* ETAPI */.etapi-options-section div {diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.css b/apps/client/src/widgets/type_widgets/options/shortcuts.cssindex f48f84f227..9bed831acf 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.css+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.css@@ -7,6 +7,7 @@background: var(--main-background-color);padding-block: 0.5em;border-bottom: 1px solid var(--main-border-color);+ margin-bottom: 1em;}> footer {@@ -21,17 +22,6 @@justify-content: space-between;}- .shortcut-group-title {- margin: 1.5em 0 0;- padding-block: 0.5em;- font-weight: bold;- color: var(--muted-text-color);- text-transform: uppercase;- font-size: 0.85em;- letter-spacing: 0.05em;- border-bottom: 1px solid var(--main-border-color);- }-.shortcut-modified-indicator {display: inline-block;width: 0.5em;diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsxindex 3a75e5b94d..69633a31f7 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx@@ -8,7 +8,7 @@ import FormTextBox from "../../react/FormTextBox";import RawHtml from "../../react/RawHtml";import OptionsRow from "./components/OptionsRow";import OptionsSection from "./components/OptionsSection";-import { useCallback, useEffect, useState } from "preact/hooks";+import { useCallback, useEffect, useMemo, useState } from "preact/hooks";import server from "../../../services/server";import options from "../../../services/options";import dialog from "../../../services/dialog";@@ -74,13 +74,16 @@ export default function ShortcutSettings() {}, [ keyboardShortcuts ]);const filterLowerCase = filter?.toLowerCase() ?? "";- const filteredKeyboardShortcuts = filter ? keyboardShortcuts.filter((action) => filterKeyboardAction(action, filterLowerCase)) : keyboardShortcuts;+ const groups = useMemo(() => groupShortcuts(keyboardShortcuts), [ keyboardShortcuts ]);+ const filteredGroups = groups+ .map((group) => ({+ ...group,+ actions: filter ? group.actions.filter((action) => filterKeyboardAction(action, filterLowerCase)) : group.actions+ }))+ .filter((group) => group.actions.length > 0);return (- <OptionsSection- className="shortcuts-options-section"- noCard- >+ <div className="shortcuts-options-section"><FormText>{t("shortcuts.multiple_shortcuts")}{" "}<RawHtml html={t("shortcuts.electron_documentation")} />@@ -93,7 +96,20 @@ export default function ShortcutSettings() {/></header>- <KeyboardShortcutList filteredKeyboardActions={filteredKeyboardShortcuts} filter={filter} />+ {filteredGroups.length > 0+ ? filteredGroups.map((group) => (+ <OptionsSection key={group.title} title={group.title}>+ {group.actions.map((action) => (+ <ShortcutRow key={action.actionName} action={action} />+ ))}+ </OptionsSection>+ ))+ : (+ <NoItems+ icon="bx bx-filter-alt"+ text={t("shortcuts.no_results", { filter })}+ />+ )}<footer><Button@@ -106,10 +122,29 @@ export default function ShortcutSettings() {onClick={resetShortcuts}/></footer>- </OptionsSection>+ </div>)}+interface ShortcutGroup {+ title: string;+ actions: ActionKeyboardShortcut[];+}++function groupShortcuts(shortcuts: KeyboardShortcut[]): ShortcutGroup[] {+ const groups: ShortcutGroup[] = [];++ for (const shortcut of shortcuts) {+ if ("separator" in shortcut) {+ groups.push({ title: shortcut.separator, actions: [] });+ } else {+ groups[groups.length - 1]?.actions.push(shortcut);+ }+ }++ return groups;+}+function isShortcutModified(action: ActionKeyboardShortcut) {return !arrayEqual(action.effectiveShortcuts ?? [], action.defaultShortcuts ?? []);}@@ -124,12 +159,7 @@ function formatDefaultShortcuts(action: ActionKeyboardShortcut) {: t("shortcuts.no_default_shortcut");}-function filterKeyboardAction(action: KeyboardShortcut, filter: string) {- // Hide separators when filtering is active.- if ("separator" in action) {- return !filter;- }-+function filterKeyboardAction(action: ActionKeyboardShortcut, filter: string) {return action.actionName.toLowerCase().includes(filter) ||(action.friendlyName && action.friendlyName.toLowerCase().includes(filter)) ||(action.defaultShortcuts ?? []).some((shortcut) => shortcut.toLowerCase().includes(filter)) ||@@ -137,47 +167,29 @@ function filterKeyboardAction(action: KeyboardShortcut, filter: string) {(action.description && action.description.toLowerCase().includes(filter));}-function KeyboardShortcutList({ filteredKeyboardActions, filter }: { filteredKeyboardActions: KeyboardShortcut[], filter: string | undefined }) {- if (filteredKeyboardActions.length === 0) {- return (- <NoItems- icon="bx bx-filter-alt"- text={t("shortcuts.no_results", { filter })}- />- );- }-+function ShortcutRow({ action }: { action: ActionKeyboardShortcut }) {return (- <div class="keyboard-shortcut-list">- {filteredKeyboardActions.map(action => (- "separator" in action- ? <h5 class="shortcut-group-title" key={`sep-${action.separator}`}>{action.separator}</h5>- : (- <OptionsRow- key={action.actionName}- name={action.actionName}- label={- <>- {isShortcutModified(action) &&- <span class="shortcut-modified-indicator" title={t("shortcuts.modified_from_default")} />}- {action.friendlyName}- </>- }- description={action.description}- >- <div class="shortcut-row-input">- <ShortcutEditor keyboardShortcut={action} />- {isShortcutModified(action) &&- <ActionButton- icon="bx bx-reset"- text={t("shortcuts.revert_to_default", { shortcuts: formatDefaultShortcuts(action) })}- onClick={() => revertShortcut(action)}- />}- </div>- </OptionsRow>- )- ))}- </div>+ <OptionsRow+ name={action.actionName}+ label={+ <>+ {isShortcutModified(action) &&+ <span class="shortcut-modified-indicator" title={t("shortcuts.modified_from_default")} />}+ {action.friendlyName}+ </>+ }+ description={action.description}+ >+ <div class="shortcut-row-input">+ <ShortcutEditor keyboardShortcut={action} />+ {isShortcutModified(action) &&+ <ActionButton+ icon="bx bx-reset"+ text={t("shortcuts.revert_to_default", { shortcuts: formatDefaultShortcuts(action) })}+ onClick={() => revertShortcut(action)}+ />}+ </div>+ </OptionsRow>);}