feat(touch_bar): reflect state for bold

This commit is contained in:
Elian Doran 2025-03-09 14:28:18 +02:00
parent ff78ab650a
commit fff140d141
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -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"),