mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-14 13:13:58 +08:00
fix(touch_bar): fix text editor commands
This commit is contained in:
parent
c2e4af1cfa
commit
0fe5f79f09
@ -2,19 +2,8 @@ import utils from "../services/utils.js";
|
|||||||
import Component from "../components/component.js";
|
import Component from "../components/component.js";
|
||||||
import appContext from "../components/app_context.js";
|
import appContext from "../components/app_context.js";
|
||||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||||
import type FNote from "../entities/fnote.js";
|
|
||||||
import type { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl, TouchBarSpacer } from "@electron/remote";
|
import type { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl, TouchBarSpacer } from "@electron/remote";
|
||||||
|
|
||||||
async function triggerTextEditorCommand(command: string, args?: object) {
|
|
||||||
const editor = await appContext.tabManager.getActiveContext().getTextEditor();
|
|
||||||
if (!editor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Fix type of editor.
|
|
||||||
(editor as any).execute(command, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class TouchBarWidget extends NoteContextAwareWidget {
|
export default class TouchBarWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
nativeImage: typeof import("electron").nativeImage;
|
nativeImage: typeof import("electron").nativeImage;
|
||||||
|
@ -510,6 +510,8 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
buildTouchBarCommand(data) {
|
buildTouchBarCommand(data) {
|
||||||
const { TouchBar, buildIcon } = data;
|
const { TouchBar, buildIcon } = data;
|
||||||
const { TouchBarSegmentedControl, TouchBarGroup, TouchBarButton } = TouchBar;
|
const { TouchBarSegmentedControl, TouchBarGroup, TouchBarButton } = TouchBar;
|
||||||
|
const { editor } = this.watchdog;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
new TouchBarSegmentedControl({
|
new TouchBarSegmentedControl({
|
||||||
segments: [
|
segments: [
|
||||||
@ -520,13 +522,13 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
change(selectedIndex, isSelected) {
|
change(selectedIndex, isSelected) {
|
||||||
switch (selectedIndex) {
|
switch (selectedIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
triggerTextEditorCommand("paragraph")
|
editor.execute("paragraph")
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
triggerTextEditorCommand("heading", { value: "heading2" });
|
editor.execute("heading", { value: "heading2" });
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
triggerTextEditorCommand("heading", { value: "heading3" });
|
editor.execute("heading", { value: "heading3" });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -536,15 +538,15 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
items: [
|
items: [
|
||||||
new TouchBarButton({
|
new TouchBarButton({
|
||||||
icon: buildIcon("NSTouchBarTextBoldTemplate"),
|
icon: buildIcon("NSTouchBarTextBoldTemplate"),
|
||||||
click: () => triggerTextEditorCommand("bold")
|
click: () => editor.execute("bold")
|
||||||
}),
|
}),
|
||||||
new TouchBarButton({
|
new TouchBarButton({
|
||||||
icon: buildIcon("NSTouchBarTextItalicTemplate"),
|
icon: buildIcon("NSTouchBarTextItalicTemplate"),
|
||||||
click: () => triggerTextEditorCommand("italic")
|
click: () => editor.execute("italic")
|
||||||
}),
|
}),
|
||||||
new TouchBarButton({
|
new TouchBarButton({
|
||||||
icon: buildIcon("NSTouchBarTextUnderlineTemplate"),
|
icon: buildIcon("NSTouchBarTextUnderlineTemplate"),
|
||||||
click: () => triggerTextEditorCommand("underline")
|
click: () => editor.execute("underline")
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user