Skip to content

Build your personal knowledge base with Trilium Notes

custom task states: tweak text editor checkbox tooltip

Adorian Doran36b53c286f12
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index ce1ea832a9..bd177cfbc5 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -757,6 +757,19 @@ table.promoted-attributes-in-tooltip th {
z-index: 32767 !important;
}
+
+/* Tooltip for text editor content, placed at the bottom of the screen to be less intruive when editing */
+.tooltip.text-editor-content-tooltip {
+ position: fixed !important;
+ inset: auto auto 1rem 1rem !important;
+ transform: none !important;
+ margin: 0 !important;
+}
+
+.tooltip.text-editor-content-tooltip .tooltip-arrow {
+ display: none;
+}
+
.pre-wrap-text {
white-space: pre-wrap;
}
@@ -2792,4 +2805,4 @@ iframe.print-iframe {
opacity: 1;
cursor: not-allowed;
}
-}
\ No newline at end of file
+}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0e24ccf937..3a806e6910 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2658,7 +2658,7 @@
"read-only": "This note is read-only."
},
"text-editor": {
- "checkbox-tooltip": "Right click for more task states. Press Ctrl+Shift+Enter to cycle between states.",
+ "checkbox-tooltip": "Right click for more task states.\nPress {{shortcut}} to cycle between states.",
"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/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.ts
index 62f62e47eb..69cb9ba102 100644
--- a/apps/client/src/widgets/type_widgets/text/config.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.ts
@@ -180,7 +180,7 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi
(config as Record<string, unknown>).editTaskStates = openCustomTaskStateConfig;
// The app's i18n translate function, so plugins can resolve Trilium translation keys.
- (config as Record<string, unknown>).translate = (key: string) => t(key);
+ (config as Record<string, unknown>).translate = (key: string, params?: Record<string, unknown>) => t(key, params);
// Set up content language.
const { contentLanguage } = opts;
diff --git a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts
index 8000dbe36b..37e5b357bf 100644
--- a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts
+++ b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts
@@ -1,6 +1,6 @@
import { DEFAULT_TASK_STATES, DONE_STATE_NAME, isAnchorState, NONE_STATE_NAME, type TaskStateDef } from "@triliumnext/commons";
import { Tooltip } from "bootstrap";
-import { Command, ListEditing, Plugin, TodoList, type Editor, type ModelElement, type ViewElement } from "ckeditor5";
+import { Command, getEnvKeystrokeText, ListEditing, Plugin, TodoList, type Editor, type ModelElement, type ViewElement } from "ckeditor5";
export const TASK_STATE_ATTRIBUTE = "taskState";
const TODO_LIST_CHECKED_ATTRIBUTE = "todoListChecked";
@@ -28,11 +28,14 @@ export default class TodoListMultistateEditing extends Plugin {
return [TodoList, ListEditing] as const;
}
+ /** Checkboxes that currently have a tooltip attached, so stale ones can be disposed. */
+ private readonly _checkboxTooltips = new Set<HTMLInputElement>();
+
init() {
const editor = this.editor;
const states = getConfiguredTaskStates(editor);
const stateByName = new Map(states.map((state) => [state.name, state]));
- const translate = (editor.config.get("translate") as ((key: string) => string) | undefined)
+ const translate = (editor.config.get("translate") as ((key: string, params?: Record<string, unknown>) => string) | undefined)
?? ((key: string) => key);
editor.model.schema.extend("$block", {allowAttributes: TASK_STATE_ATTRIBUTE});
@@ -85,9 +88,21 @@ export default class TodoListMultistateEditing extends Plugin {
if (!domRoot) {
return;
}
+ // CKEditor recreates the checkbox element when a todo item reconverts
+ // (e.g. on click); dispose tooltips left on the detached old checkboxes.
+ for (const input of this._checkboxTooltips) {
+ if (!input.isConnected) {
+ Tooltip.getInstance(input)?.dispose();
+ this._checkboxTooltips.delete(input);
+ }
+ }
for (const input of domRoot.querySelectorAll<HTMLInputElement>(".todo-list__label input[type=\"checkbox\"]")) {
if (!Tooltip.getInstance(input)) {
- new Tooltip(input, {title: translate("text-editor.checkbox-tooltip")});
+ const title = translate("text-editor.checkbox-tooltip", {
+ shortcut: getEnvKeystrokeText("Ctrl+Shift+Enter")
+ });
+ new Tooltip(input, {title, customClass: "text-editor-content-tooltip"});
+ this._checkboxTooltips.add(input);
}
}
});
@@ -146,6 +161,14 @@ export default class TodoListMultistateEditing extends Plugin {
});
}
+ override destroy() {
+ for (const input of this._checkboxTooltips) {
+ Tooltip.getInstance(input)?.dispose();
+ }
+ this._checkboxTooltips.clear();
+ super.destroy();
+ }
+
}
class SetTaskStateCommand extends Command {