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): replace default shortcuts column with a revert button
Elian Doran0f4c4736345f
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 624652c384..17409c1c10 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1726,13 +1726,14 @@"type_text_to_filter": "Type text to filter shortcuts...","action_name": "Action name","shortcuts": "Shortcuts",- "default_shortcuts": "Default 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?","no_results": "No shortcuts found matching '{{filter}}'",- "modified_from_default": "This shortcut has been changed from its default."+ "modified_from_default": "This shortcut has been changed from its default.",+ "revert_to_default": "Revert to default ({{shortcuts}})",+ "no_default_shortcut": "no shortcut"},"spellcheck": {"title": "Spell Check",diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.css b/apps/client/src/widgets/type_widgets/options/shortcuts.cssindex fae7c0221b..8c9ce73dea 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.css+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.css@@ -28,6 +28,13 @@width: 25%;}+ th.revert-col,+ td.revert-col {+ width: 1%;+ text-align: center;+ white-space: nowrap;+ }+.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 8547e6bb17..cb692198e7 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx@@ -1,6 +1,7 @@import { ActionKeyboardShortcut, KeyboardShortcut, OptionNames } from "@triliumnext/commons";import { t } from "../../../services/i18n";import { arrayEqual, reloadFrontendApp } from "../../../services/utils";+import ActionButton from "../../react/ActionButton";import Button from "../../react/Button";import FormText from "../../react/FormText";import FormTextBox from "../../react/FormTextBox";@@ -112,6 +113,16 @@ function isShortcutModified(action: ActionKeyboardShortcut) {return !arrayEqual(action.effectiveShortcuts ?? [], action.defaultShortcuts ?? []);}+function revertShortcut(action: ActionKeyboardShortcut) {+ void options.save(getOptionName(action.actionName), JSON.stringify(action.defaultShortcuts ?? []));+}++function formatDefaultShortcuts(action: ActionKeyboardShortcut) {+ return action.defaultShortcuts?.length+ ? action.defaultShortcuts.join(", ")+ : t("shortcuts.no_default_shortcut");+}+function filterKeyboardAction(action: KeyboardShortcut, filter: string) {// Hide separators when filtering is active.if ("separator" in action) {@@ -132,7 +143,7 @@ function KeyboardShortcutTable({ filteredKeyboardActions, filter }: { filteredKe<tr class="text-nowrap"><th>{t("shortcuts.action_name")}</th><th>{t("shortcuts.shortcuts")}</th>- <th>{t("shortcuts.default_shortcuts")}</th>+ <th class="revert-col" /><th>{t("shortcuts.description")}</th></tr></thead>@@ -157,7 +168,14 @@ function KeyboardShortcutTable({ filteredKeyboardActions, filter }: { filteredKe<td><ShortcutEditor keyboardShortcut={action} /></td>- <td>{action.defaultShortcuts?.join(", ")}</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></>)}