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
client/text editor/collapsible blocks: format keyboard shortcut in the content hint
Adorian Doran6a8adce25b83
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 6cfe9f9aae..d4b7fd0d0e 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3133,7 +3133,7 @@"collapsible-select-label": "Select collapsible block","collapsible-title-placeholder": "Summary","collapsible-toggle-label": "Toggle collapsible block",- "collapsible-tooltip": "Click on the arrow or press {{shortcut}} to collapse/expand.",+ "collapsible-tooltip": "Click on the arrow or press {{- shortcut}} to collapse/expand.","edit-states-tooltip": "Edit task states","unknown-task-state": "Undefined custom task state","task-state-dropped": "Dropped custom task state definition \"{{title}}\" ({{id}}) due to: {{reason}}",diff --git a/packages/ckeditor5-collapsible/package.json b/packages/ckeditor5-collapsible/package.jsonindex 85cf1ad2ea..d8d9d6d847 100644--- a/packages/ckeditor5-collapsible/package.json+++ b/packages/ckeditor5-collapsible/package.json@@ -25,7 +25,8 @@"vitest": "4.1.10"},"dependencies": {- "@triliumnext/ckeditor5-utils": "workspace:*"+ "@triliumnext/ckeditor5-utils": "workspace:*",+ "@triliumnext/commons": "workspace:*"},"peerDependencies": {"bootstrap": "^5.3.0",diff --git a/packages/ckeditor5-collapsible/src/collapsible-editing.ts b/packages/ckeditor5-collapsible/src/collapsible-editing.tsindex 171f1e8fce..c1dae47441 100644--- a/packages/ckeditor5-collapsible/src/collapsible-editing.ts+++ b/packages/ckeditor5-collapsible/src/collapsible-editing.ts@@ -1,10 +1,19 @@-import { Plugin, Enter, Delete, enableViewPlaceholder, getEnvKeystrokeText, type ViewDocumentEnterEvent, type ViewDocumentDeleteEvent, type ViewDocumentArrowKeyEvent } from "ckeditor5";+import { Plugin, Enter, Delete, enableViewPlaceholder, env, type ViewDocumentEnterEvent, type ViewDocumentDeleteEvent, type ViewDocumentArrowKeyEvent } from "ckeditor5";+import { formatShortcut, joinShortcut } from "@triliumnext/commons";import { ContentHintManager, type HintHandle } from "@triliumnext/ckeditor5-utils";import BlockDragHandle from "./block-drag-handle.js";import CollapsibleCommand from "./collapsible-command.js";type TranslateFn = (key: string, params?: Record<string, unknown>) => string;+/**+ * The keyboard shortcut for toggling a collapsible's `open` state. Shared as+ * a single source of truth between the `Ctrl+Enter` DOM keydown handler in+ * {@link CollapsibleEditing#onDomKeydown} and the summary hint's rendered+ * label — a rebinding in one has to be mirrored in the other.+ */+const TOGGLE_SHORTCUT = "Ctrl+Enter";+/*** Dwell delay before hover or a stationary caret pops a summary/handle hint.* Long enough that mouse flyovers don't spawn a popup, short enough that@@ -871,10 +880,13 @@ export default class CollapsibleEditing extends Plugin {const editor = this.editor;const t = this.translate();const title = t("text-editor.collapsible-tooltip", {- shortcut: getEnvKeystrokeText("Ctrl+Enter")+ shortcut: renderToggleShortcut(t)});const manager = new ContentHintManager({- tooltipOptions: { customClass: "text-editor-content-tooltip" },+ tooltipOptions: {+ sanitize: false,+ customClass: "text-editor-content-tooltip"+ },autoHideAfterMs: HINT_AUTO_HIDE_MS});this.summaryHintManager = manager;@@ -1252,3 +1264,15 @@ export default class CollapsibleEditing extends Plugin {return true;}}++/**+ * Render the toggle shortcut as `<kbd>Ctrl</kbd>+<kbd>Enter</kbd>` (or+ * `<kbd>⌃</kbd><kbd>↩</kbd>` on macOS). Uses the shared `formatShortcut` /+ * `joinShortcut` from `@triliumnext/commons` so key labels flow through the+ * same i18n and Mac-glyph rules as the rest of the app.+ */+function renderToggleShortcut(translate: TranslateFn): string {+ const kbdTokens = formatShortcut(TOGGLE_SHORTCUT, translate, env.isMac)+ .map((token: string) => `<kbd>${token}</kbd>`);+ return joinShortcut(kbdTokens, env.isMac);+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 1dc06c8635..66056af627 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1168,6 +1168,9 @@ importers:'@triliumnext/ckeditor5-utils':specifier: workspace:*version: link:../ckeditor5-utils+ '@triliumnext/commons':+ specifier: workspace:*+ version: link:../commonsbootstrap:specifier: ^5.3.0version: 5.3.8(@popperjs/[email protected])