Skip to content

Build your personal knowledge base with Trilium Notes

feat(touch_bar): reflect state for bold

Elian Doranfff140d141c4
diff --git a/src/public/app/widgets/touch_bar.ts b/src/public/app/widgets/touch_bar.ts
index 25db457c3b..d3da685e2a 100644
--- a/src/public/app/widgets/touch_bar.ts
+++ b/src/public/app/widgets/touch_bar.ts
@@ -4,6 +4,10 @@ import appContext from "../components/app_context.js";
import NoteContextAwareWidget from "./note_context_aware_widget.js";
import type { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl, TouchBarSpacer } from "@electron/remote";
+export function buildSelectedBackgroundColor(isSelected: boolean) {
+ return isSelected ? "#ff0000" : undefined;
+}
+
export default class TouchBarWidget extends NoteContextAwareWidget {
nativeImage: typeof import("electron").nativeImage;
diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js
index a6efbbe112..79e32d6039 100644
--- a/src/public/app/widgets/type_widgets/editable_text.js
+++ b/src/public/app/widgets/type_widgets/editable_text.js
@@ -16,6 +16,7 @@ import toast from "../../services/toast.js";
import { getMermaidConfig } from "../mermaid.js";
import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js";
import { buildConfig, buildToolbarConfig } from "./ckeditor/toolbars.js";
+import { buildSelectedBackgroundColor } from "../touch_bar.js";
const ENABLE_INSPECTOR = false;
@@ -250,6 +251,9 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
CKEditorInspector.attach(editor);
}
+ // Touch bar integration
+ editor.commands.get("bold").on("change", () => this.triggerCommand("refreshTouchBar"));
+
return editor;
});
@@ -538,7 +542,8 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
items: [
new TouchBarButton({
icon: buildIcon("NSTouchBarTextBoldTemplate"),
- click: () => editor.execute("bold")
+ click: () => editor.execute("bold"),
+ backgroundColor: buildSelectedBackgroundColor(editor.commands.get("bold").value)
}),
new TouchBarButton({
icon: buildIcon("NSTouchBarTextItalicTemplate"),