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 options row instead of table
Elian Doran6a40a3d2950c
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 17409c1c10..d9b1b2b882 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1724,9 +1724,6 @@"multiple_shortcuts": "Multiple shortcuts for the same action can be separated by comma.","electron_documentation": "See <a href=\"https://www.electronjs.org/docs/latest/api/accelerator\">Electron documentation</a> for available modifiers and key codes.","type_text_to_filter": "Type text to filter shortcuts...",- "action_name": "Action name",- "shortcuts": "Shortcuts",- "description": "Description","reload_app": "Reload app to apply changes","set_all_to_default": "Set all shortcuts to the default","confirm_reset": "Do you really want to reset all keyboard shortcuts to the default?",diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.css b/apps/client/src/widgets/type_widgets/options/shortcuts.cssindex 8c9ce73dea..f48f84f227 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.css+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.css@@ -21,37 +21,34 @@justify-content: space-between;}- table {- width: 100%;-- th {- width: 25%;- }-- th.revert-col,- td.revert-col {- width: 1%;- text-align: center;- white-space: nowrap;- }+ .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;- height: 0.5em;- margin-right: 0.5em;- border-radius: 50%;- background-color: var(--link-color);- vertical-align: middle;- }+ .shortcut-modified-indicator {+ display: inline-block;+ width: 0.5em;+ height: 0.5em;+ margin-right: 0.5em;+ border-radius: 50%;+ background-color: var(--link-color);+ vertical-align: middle;+ }- .separator {- background-color: var(--accented-background-color);- font-weight: bold;+ .shortcut-row-input {+ display: flex;+ align-items: center;+ gap: 0.5em;+ }- &:first-of-type {- padding-top: 1em;- }- }+ .shortcut-row-input > input {+ min-width: 220px;}}diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsxindex cb692198e7..3a75e5b94d 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx@@ -6,6 +6,7 @@ import Button from "../../react/Button";import FormText from "../../react/FormText";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 server from "../../../services/server";@@ -92,7 +93,7 @@ export default function ShortcutSettings() {/></header>- <KeyboardShortcutTable filteredKeyboardActions={filteredKeyboardShortcuts} filter={filter} />+ <KeyboardShortcutList filteredKeyboardActions={filteredKeyboardShortcuts} filter={filter} /><footer><Button@@ -136,63 +137,47 @@ function filterKeyboardAction(action: KeyboardShortcut, filter: string) {(action.description && action.description.toLowerCase().includes(filter));}-function KeyboardShortcutTable({ filteredKeyboardActions, filter }: { filteredKeyboardActions: KeyboardShortcut[], filter: string | undefined }) {+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 })}+ />+ );+ }+return (- <table class="keyboard-shortcut-table" cellPadding="10">- <thead>- <tr class="text-nowrap">- <th>{t("shortcuts.action_name")}</th>- <th>{t("shortcuts.shortcuts")}</th>- <th class="revert-col" />- <th>{t("shortcuts.description")}</th>- </tr>- </thead>- <tbody>- {filteredKeyboardActions.length > 0- ? filteredKeyboardActions.map(action => (- <tr>- {"separator" in action ?- <td class="separator" colspan={4} style={{- backgroundColor: "var(--accented-background-color)",- fontWeight: "bold"- }}>- {action.separator}- </td>- : (- <>- <td>+ <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}- </td>- <td>- <ShortcutEditor keyboardShortcut={action} />- </td>- <td class="revert-col">- {isShortcutModified(action) &&- <ActionButton- icon="bx bx-reset"- text={t("shortcuts.revert_to_default", { shortcuts: formatDefaultShortcuts(action) })}- onClick={() => revertShortcut(action)}- />}- </td>- <td>{action.description}</td>- </>- )}- </tr>- ))- : (- <tr>- <td colspan={4} class="text-center">- <NoItems- icon="bx bx-filter-alt"- text={t("shortcuts.no_results", { filter })}- />- </td>- </tr>- )}- </tbody>- </table>+ </>+ }+ 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>);}