Skip to content

Build your personal knowledge base with Trilium Notes

chore(electron): remove touchbar support

Elian Doranfb5f90ad1c53
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 07bab280f9..257d0b7893 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -1,7 +1,6 @@
import type { CKTextEditor } from "@triliumnext/ckeditor5";
import type CodeMirror from "@triliumnext/codemirror";
import { type LOCALE_IDS, SqlExecuteResponse } from "@triliumnext/commons";
-import type { NativeImage, TouchBar } from "electron";
import { ColumnComponent } from "tabulator-tables";
import type { Attribute } from "../services/attribute_parser.js";
@@ -14,7 +13,7 @@ import type LoadResults from "../services/load_results.js";
import type { CreateNoteOpts } from "../services/note_create.js";
import options from "../services/options.js";
import toast from "../services/toast.js";
-import utils, { hasTouchBar } from "../services/utils.js";
+import utils from "../services/utils.js";
import { ReactWrappedWidget } from "../widgets/basic_widget.js";
import type RootContainer from "../widgets/containers/root_container.js";
import { AddLinkOpts } from "../widgets/dialogs/add_link.jsx";
@@ -37,7 +36,6 @@ import RootCommandExecutor from "./root_command_executor.js";
import ShortcutComponent from "./shortcut_component.js";
import { StartupChecks } from "./startup_checks.js";
import TabManager from "./tab_manager.js";
-import TouchBarComponent from "./touch_bar.js";
import zoomComponent from "./zoom.js";
interface Layout {
@@ -392,11 +390,6 @@ export type CommandMappings = {
columnToDelete?: ColumnComponent;
};
- buildTouchBar: CommandData & {
- TouchBar: typeof TouchBar;
- buildIcon(name: string): NativeImage;
- };
- refreshTouchBar: CommandData;
reloadTextEditor: CommandData;
chooseNoteType: CommandData & {
callback: ChooseNoteTypeCallback
@@ -622,10 +615,6 @@ export class AppContext extends Component {
if (utils.isElectron()) {
this.child(zoomComponent);
}
-
- if (hasTouchBar) {
- this.child(new TouchBarComponent());
- }
}
renderWidgets() {
diff --git a/apps/client/src/components/touch_bar.ts b/apps/client/src/components/touch_bar.ts
deleted file mode 100644
index 226318a927..0000000000
--- a/apps/client/src/components/touch_bar.ts
+++ /dev/null
@@ -1,135 +0,0 @@
-import utils from "../services/utils.js";
-import Component from "./component.js";
-import appContext from "./app_context.js";
-import type { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl, TouchBarSpacer } from "@electron/remote";
-
-export type TouchBarItem = (TouchBarButton | TouchBarSpacer | TouchBarGroup | TouchBarSegmentedControl);
-
-export function buildSelectedBackgroundColor(isSelected: boolean) {
- return isSelected ? "#757575" : undefined;
-}
-
-export default class TouchBarComponent extends Component {
-
- nativeImage: typeof import("electron").nativeImage;
- remote: typeof import("@electron/remote");
- lastFocusedComponent?: Component;
- private $activeModal?: JQuery<HTMLElement>;
-
- constructor() {
- super();
- this.nativeImage = utils.dynamicRequire("electron").nativeImage;
- this.remote = utils.dynamicRequire("@electron/remote") as typeof import("@electron/remote");
- this.$widget = $("<div>");
-
- $(window).on("focusin", async (e) => {
- const focusedEl = e.target as unknown as HTMLElement;
- const $target = $(focusedEl);
-
- this.$activeModal = $target.closest(".modal-dialog");
- this.lastFocusedComponent = appContext.getComponentByEl(focusedEl);
- this.#refreshTouchBar();
- });
- }
-
- buildIcon(name: string) {
- const sourceImage = this.nativeImage.createFromNamedImage(name, [-1, 0, 1]);
- const { width, height } = sourceImage.getSize();
- const newImage = this.nativeImage.createEmpty();
- newImage.addRepresentation({
- scaleFactor: 1,
- width: width / 2,
- height: height / 2,
- buffer: sourceImage.resize({ height: height / 2 }).toBitmap()
- });
- newImage.addRepresentation({
- scaleFactor: 2,
- width: width,
- height: height,
- buffer: sourceImage.toBitmap()
- });
- return newImage;
- }
-
- #refreshTouchBar() {
- const { TouchBar } = this.remote;
- const parentComponent = this.lastFocusedComponent;
- let touchBar: Electron.CrossProcessExports.TouchBar | null = null;
-
- if (this.$activeModal?.length) {
- touchBar = this.#buildModalTouchBar();
- } else if (parentComponent) {
- const items = parentComponent.triggerCommand("buildTouchBar", {
- TouchBar,
- buildIcon: this.buildIcon.bind(this)
- }) as unknown as TouchBarItem[];
- touchBar = this.#buildTouchBar(items);
- }
-
- if (touchBar) {
- this.remote.getCurrentWindow().setTouchBar(touchBar);
- }
- }
-
- #buildModalTouchBar() {
- const { TouchBar } = this.remote;
- const { TouchBarButton, TouchBarLabel, TouchBarSpacer } = this.remote.TouchBar;
- const items: TouchBarItem[] = [];
-
- // Look for the modal title.
- const $title = this.$activeModal?.find(".modal-title");
- if ($title?.length) {
- items.push(new TouchBarLabel({ label: $title.text() }))
- }
-
- items.push(new TouchBarSpacer({ size: "flexible" }));
-
- // Look for buttons in the modal.
- const $buttons = this.$activeModal?.find(".modal-footer button");
- for (const button of $buttons ?? []) {
- items.push(new TouchBarButton({
- label: button.innerText,
- click: () => button.click(),
- enabled: !button.hasAttribute("disabled")
- }));
- }
-
- items.push(new TouchBarSpacer({ size: "flexible" }));
- return new TouchBar({ items });
- }
-
- #buildTouchBar(componentSpecificItems?: TouchBarItem[]) {
- const { TouchBar } = this.remote;
- const { TouchBarButton, TouchBarSpacer, TouchBarGroup, TouchBarSegmentedControl, TouchBarOtherItemsProxy } = this.remote.TouchBar;
-
- // Disregard recursive calls or empty results.
- if (!componentSpecificItems || "then" in componentSpecificItems) {
- componentSpecificItems = [];
- }
-
- const items = [
- new TouchBarButton({
- icon: this.buildIcon("NSTouchBarComposeTemplate"),
- click: () => this.triggerCommand("createNoteIntoInbox")
- }),
- new TouchBarSpacer({ size: "small" }),
- ...componentSpecificItems,
- new TouchBarSpacer({ size: "flexible" }),
- new TouchBarOtherItemsProxy(),
- new TouchBarButton({
- icon: this.buildIcon("NSTouchBarAddDetailTemplate"),
- click: () => this.triggerCommand("jumpToNote")
- })
- ].flat();
-
- console.log("Update ", items);
- return new TouchBar({
- items
- });
- }
-
- refreshTouchBarEvent() {
- this.#refreshTouchBar();
- }
-
-}
diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts
index 2bfa8e763c..e6cbdc3986 100644
--- a/apps/client/src/services/utils.ts
+++ b/apps/client/src/services/utils.ts
@@ -161,8 +161,6 @@ export function isMac() {
return navigator.platform.indexOf("Mac") > -1;
}
-export const hasTouchBar = (isMac() && isElectron());
-
export function isCtrlKey(evt: KeyboardEvent | MouseEvent | JQuery.ClickEvent | JQuery.ContextMenuEvent | JQuery.TriggeredEvent | React.PointerEvent<HTMLCanvasElement> | JQueryEventObject) {
return (!isMac() && evt.ctrlKey) || (isMac() && evt.metaKey);
}
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 170db6af73..b75f2ffc2f 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -21,7 +21,6 @@ import Dropdown from "../../react/Dropdown";
import { FormListItem } from "../../react/FormList";
import { useNoteLabel, useNoteLabelBoolean, useResizeObserver, useSpacedUpdate, useTriliumEvent, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";
import { ParentComponent } from "../../react/react_utils";
-import TouchBar, { TouchBarButton, TouchBarLabel, TouchBarSegmentedControl, TouchBarSpacer } from "../../react/TouchBar";
import { ViewModeProps } from "../interface";
import { changeEvent, newEvent } from "./api";
import Calendar from "./calendar";
@@ -179,7 +178,6 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
}
}}
/>
- <CalendarTouchBar calendarRef={calendarRef} />
</div>
);
}
@@ -405,40 +403,6 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u
return { eventDidMount };
}
-function CalendarTouchBar({ calendarRef }: { calendarRef: RefObject<FullCalendar> }) {
- const { title, viewType } = useOnDatesSet(calendarRef);
-
- return (
- <TouchBar>
- <TouchBarSegmentedControl
- mode="single"
- segments={CALENDAR_VIEWS.map(({ name }) => ({
- label: name,
- }))}
- selectedIndex={CALENDAR_VIEWS.findIndex(v => v.type === viewType) ?? 0}
- onChange={(selectedIndex) => calendarRef.current?.changeView(CALENDAR_VIEWS[selectedIndex].type)}
- />
-
- <TouchBarSpacer size="flexible" />
- <TouchBarLabel label={title ?? ""} />
- <TouchBarSpacer size="flexible" />
-
- <TouchBarButton
- label={t("calendar.today")}
- click={() => calendarRef.current?.today()}
- />
- <TouchBarButton
- icon="NSImageNameTouchBarGoBackTemplate"
- click={() => calendarRef.current?.prev()}
- />
- <TouchBarButton
- icon="NSImageNameTouchBarGoForwardTemplate"
- click={() => calendarRef.current?.next()}
- />
- </TouchBar>
- );
-}
-
function useOnDatesSet(calendarRef: RefObject<FullCalendar>) {
const [ title, setTitle ] = useState<string>();
const [ viewType ,setViewType ] = useState<string>();
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 625bf534e8..5ce5a3c015 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -3,7 +3,7 @@ import "./index.css";
import { divIcon, GPXOptions, LatLng, LeafletMouseEvent } from "leaflet";
import markerIcon from "leaflet/dist/images/marker-icon.png";
import markerIconShadow from "leaflet/dist/images/marker-shadow.png";
-import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
+import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import appContext from "../../../components/app_context";
import FNote from "../../../entities/fnote";
@@ -17,8 +17,6 @@ import CollectionProperties from "../../note_bars/CollectionProperties";
import ActionButton from "../../react/ActionButton";
import { ButtonOrActionButton } from "../../react/Button";
import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";
-import { ParentComponent } from "../../react/react_utils";
-import TouchBar, { TouchBarButton, TouchBarSlider } from "../../react/TouchBar";
import { ViewModeProps } from "../interface";
import { createNewNote, moveMarker } from "./api";
import openContextMenu, { openMapContextMenu } from "./context_menu";
@@ -166,7 +164,6 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
>
{notes.map(note => <NoteWrapper note={note} isReadOnly={isReadOnly} hideLabels={hideLabels} />)}
</Map>}
- <GeoMapTouchBar state={state} map={apiRef.current} />
</div>
);
}
@@ -316,38 +313,3 @@ function buildIcon(bxIconClass: string, colorClass?: string, title?: string, not
});
}
-function GeoMapTouchBar({ state, map }: { state: State, map: L.Map | null | undefined }) {
- const [ currentZoom, setCurrentZoom ] = useState<number>();
- const parentComponent = useContext(ParentComponent);
-
- useEffect(() => {
- if (!map) return;
-
- function onZoomChanged() {
- setCurrentZoom(map?.getZoom());
- }
-
- map.on("zoom", onZoomChanged);
- return () => map.off("zoom", onZoomChanged);
- }, [ map ]);
-
- return map && currentZoom && (
- <TouchBar>
- <TouchBarSlider
- label="Zoom"
- value={currentZoom}
- minValue={map.getMinZoom()}
- maxValue={map.getMaxZoom()}
- onChange={(newValue) => {
- setCurrentZoom(newValue);
- map.setZoom(newValue);
- }}
- />
- <TouchBarButton
- label="New geo note"
- click={() => parentComponent?.triggerCommand("geoMapCreateChildNote")}
- enabled={state === State.Normal}
- />
- </TouchBar>
- );
-}
diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts
index 296137b16b..f4b68f08a8 100644
--- a/apps/client/src/widgets/note_tree.ts
+++ b/apps/client/src/widgets/note_tree.ts
@@ -7,7 +7,6 @@ import "./note_tree.css";
import appContext, { type CommandListenerData, type EventData } from "../components/app_context.js";
import type { SetNoteOpts } from "../components/note_context.js";
-import type { TouchBarItem } from "../components/touch_bar.js";
import type FBranch from "../entities/fbranch.js";
import type FNote from "../entities/fnote.js";
import contextMenu from "../menus/context_menu.js";
@@ -1788,41 +1787,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
appContext.tabManager.getActiveContext()?.setNote(resp.note.noteId);
}
- buildTouchBarCommand({ TouchBar, buildIcon }: CommandListenerData<"buildTouchBar">) {
- const triggerCommand = (command: TreeCommandNames) => {
- const node = this.getActiveNode();
- if (!node) return;
- const notePath = treeService.getNotePath(node);
-
- this.triggerCommand<TreeCommandNames>(command, {
- node,
- notePath,
- noteId: node.data.noteId,
- selectedOrActiveBranchIds: this.getSelectedOrActiveBranchIds(node),
- selectedOrActiveNoteIds: this.getSelectedOrActiveNoteIds(node)
- });
- };
-
- const items: TouchBarItem[] = [
- new TouchBar.TouchBarButton({
- icon: buildIcon("NSImageNameTouchBarAddTemplate"),
- click: () => {
- const node = this.getActiveNode();
- if (!node) return;
- const notePath = treeService.getNotePath(node);
- noteCreateService.createNote(notePath, {
- isProtected: node.data.isProtected
- });
- }
- }),
- new TouchBar.TouchBarButton({
- icon: buildIcon("NSImageNameTouchBarDeleteTemplate"),
- click: () => triggerCommand("deleteNotes")
- })
- ];
-
- return items;
- }
}
function buildEnhanceTitle() {
diff --git a/apps/client/src/widgets/react/TouchBar.tsx b/apps/client/src/widgets/react/TouchBar.tsx
deleted file mode 100644
index 02918d0a36..0000000000
--- a/apps/client/src/widgets/react/TouchBar.tsx
+++ /dev/null
@@ -1,232 +0,0 @@
-import { useContext, useEffect, useMemo, useState } from "preact/hooks";
-import { ParentComponent } from "./react_utils";
-import { ComponentChildren, createContext } from "preact";
-import { TouchBarItem } from "../../components/touch_bar";
-import { dynamicRequire, isElectron, isMac } from "../../services/utils";
-
-interface TouchBarProps {
- children: ComponentChildren;
-}
-
-interface LabelProps {
- label: string;
-}
-
-interface SliderProps {
- label: string;
- value: number;
- minValue: number;
- maxValue: number;
- onChange: (newValue: number) => void;
-}
-
-interface ButtonProps {
- label?: string;
- icon?: string;
- click: () => void;
- enabled?: boolean;
- backgroundColor?: string;
-}
-
-interface SpacerProps {
- size: "flexible" | "large" | "small";
-}
-
-interface SegmentedControlProps {
- mode: "single" | "buttons";
- segments: {
- label?: string;
- icon?: string;
- onClick?: () => void;
- }[];
- selectedIndex?: number;
- onChange?: (selectedIndex: number, isSelected: boolean) => void;
-}
-
-interface TouchBarContextApi {
- addItem(item: TouchBarItem): void;
- TouchBar: typeof Electron.TouchBar;
- nativeImage: typeof Electron.nativeImage;
-}
-
-const TouchBarContext = createContext<TouchBarContextApi | null>(null);
-
-export default function TouchBar({ children }: TouchBarProps) {
- if (!isElectron() || !isMac()) {
- return;
- }
-
- const [ isFocused, setIsFocused ] = useState(false);
- const parentComponent = useContext(ParentComponent);
- const remote = dynamicRequire("@electron/remote") as typeof import("@electron/remote");
- const items: TouchBarItem[] = [];
-
- const api: TouchBarContextApi = {
- TouchBar: remote.TouchBar,
- nativeImage: remote.nativeImage,
- addItem: (item) => {
- items.push(item);
- }
- };
-
- useEffect(() => {
- const el = parentComponent?.$widget[0];
- if (!el) return;
-
- function onFocusGained() {
- setIsFocused(true);
- }
-
- function onFocusLost() {
- setIsFocused(false);
- }
-
- el.addEventListener("focusin", onFocusGained);
- el.addEventListener("focusout", onFocusLost);
- return () => {
- el.removeEventListener("focusin", onFocusGained);
- el.removeEventListener("focusout", onFocusLost);
- }
- }, []);
-
- useEffect(() => {
- if (isFocused) {
- remote.getCurrentWindow().setTouchBar(new remote.TouchBar({ items }));
- }
- });
-
- return (
- <TouchBarContext.Provider value={api}>
- {children}
- </TouchBarContext.Provider>
- );
-}
-
-export function TouchBarLabel({ label }: LabelProps) {
- const api = useContext(TouchBarContext);
-
- if (api) {
- const item = new api.TouchBar.TouchBarLabel({
- label
- });
- api.addItem(item);
- }
-
- return <></>;
-}
-
-export function TouchBarSlider({ label, value, minValue, maxValue, onChange }: SliderProps) {
- const api = useContext(TouchBarContext);
-
- if (api) {
- const item = new api.TouchBar.TouchBarSlider({
- label,
- value, minValue, maxValue,
- change: onChange
- });
- api.addItem(item);
- }
-
- return <></>;
-}
-
-export function TouchBarButton({ label, icon, click, enabled, backgroundColor }: ButtonProps) {
- const api = useContext(TouchBarContext);
- const item = useMemo(() => {
- if (!api) return null;
- return new api.TouchBar.TouchBarButton({
- label, click, enabled,
- icon: icon ? buildIcon(api.nativeImage, icon) : undefined,
- backgroundColor
- });
- }, [ label, icon ]);
-
- if (item && api) {
- api.addItem(item);
- }
-
- return <></>;
-}
-
-export function TouchBarSegmentedControl({ mode, segments, selectedIndex, onChange }: SegmentedControlProps) {
- const api = useContext(TouchBarContext);
-
- if (api) {
- const processedSegments: Electron.SegmentedControlSegment[] = segments.map(({icon, ...restProps}) => ({
- ...restProps,
- icon: icon ? buildIcon(api.nativeImage, icon) : undefined
- }));
- const item = new api.TouchBar.TouchBarSegmentedControl({
- mode, selectedIndex,
- segments: processedSegments,
- change: (selectedIndex, isSelected) => {
- if (segments[selectedIndex].onClick) {
- segments[selectedIndex].onClick();
- } else if (onChange) {
- onChange(selectedIndex, isSelected);
- }
- }
- });
- api.addItem(item);
- }
-
- return <></>;
-}
-
-export function TouchBarGroup({ children }: { children: ComponentChildren }) {
- const remote = dynamicRequire("@electron/remote") as typeof import("@electron/remote");
- const items: TouchBarItem[] = [];
-
- const api: TouchBarContextApi = {
- TouchBar: remote.TouchBar,
- nativeImage: remote.nativeImage,
- addItem: (item) => {
- items.push(item);
- }
- };
-
- if (api) {
- const item = new api.TouchBar.TouchBarGroup({
- items: new api.TouchBar({ items })
- });
- api.addItem(item);
- }
-
- return <>
- <TouchBarContext.Provider value={api}>
- {children}
- </TouchBarContext.Provider>
- </>;
-}
-
-export function TouchBarSpacer({ size }: SpacerProps) {
- const api = useContext(TouchBarContext);
-
- if (api) {
- const item = new api.TouchBar.TouchBarSpacer({
- size
- });
- api.addItem(item);
- }
-
- return <></>;
-}
-
-function buildIcon(nativeImage: typeof Electron.nativeImage, name: string) {
- const sourceImage = nativeImage.createFromNamedImage(name, [-1, 0, 1]);
- const { width, height } = sourceImage.getSize();
- const newImage = nativeImage.createEmpty();
- newImage.addRepresentation({
- scaleFactor: 1,
- width: width / 2,
- height: height / 2,
- buffer: sourceImage.resize({ height: height / 2 }).toBitmap()
- });
- newImage.addRepresentation({
- scaleFactor: 2,
- width: width,
- height: height,
- buffer: sourceImage.toBitmap()
- });
- return newImage;
-}
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx
index 2ad2a83a16..30517f0297 100644
--- a/apps/client/src/widgets/type_widgets/code/Code.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Code.tsx
@@ -5,13 +5,12 @@ import { NoteType } from "@triliumnext/commons";
import { Ref } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
-import appContext, { CommandListenerData } from "../../../components/app_context";
+import { CommandListenerData } from "../../../components/app_context";
import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import utils from "../../../services/utils";
import { useColorScheme, useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteBlob, useNoteLabelInt, useNoteLabelOptionalBool, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
import { refToJQuerySelector } from "../../react/react_utils";
-import TouchBar, { TouchBarButton } from "../../react/TouchBar";
import { CODE_THEME_DEFAULT_PREFIX as DEFAULT_PREFIX } from "../constants";
import { TypeWidgetProps } from "../type_widget";
import CodeMirror, { CodeMirrorProps } from "./CodeMirror";
@@ -128,36 +127,28 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC
useKeyboardShortcuts("code-detail", containerRef, parentComponent, ntxId);
return (
- <>
- <CodeEditor
- ntxId={ntxId} parentComponent={parentComponent}
- editorRef={combinedEditorRef} containerRef={containerRef}
- mime={mime ?? "text/plain"}
- className="note-detail-code-editor"
- placeholder={placeholder ?? t("editable_code.placeholder")}
- vimKeybindings={vimKeymapEnabled}
- tabIndex={300}
- onContentChanged={() => {
- if (debounceUpdate) {
- spacedUpdate.resetUpdateTimer();
- }
- spacedUpdate.scheduleUpdate();
- if (editorRef.current && onContentChanged) {
- onContentChanged(editorRef.current.getText());
- }
- }}
- {...editorProps}
- {...(noteTabWidth != null && { indentSize: noteTabWidth })}
- {...(noteUseTabs != null && { useTabs: noteUseTabs })}
- {...(noteWrapLines != null && { lineWrapping: noteWrapLines })}
- />
-
- <TouchBar>
- {(note?.mime.startsWith("application/javascript") || note?.mime === "text/x-sqlite;schema=trilium") && (
- <TouchBarButton icon="NSImageNameTouchBarPlayTemplate" click={() => appContext.triggerCommand("runActiveNote")} />
- )}
- </TouchBar>
- </>
+ <CodeEditor
+ ntxId={ntxId} parentComponent={parentComponent}
+ editorRef={combinedEditorRef} containerRef={containerRef}
+ mime={mime ?? "text/plain"}
+ className="note-detail-code-editor"
+ placeholder={placeholder ?? t("editable_code.placeholder")}
+ vimKeybindings={vimKeymapEnabled}
+ tabIndex={300}
+ onContentChanged={() => {
+ if (debounceUpdate) {
+ spacedUpdate.resetUpdateTimer();
+ }
+ spacedUpdate.scheduleUpdate();
+ if (editorRef.current && onContentChanged) {
+ onContentChanged(editorRef.current.getText());
+ }
+ }}
+ {...editorProps}
+ {...(noteTabWidth != null && { indentSize: noteTabWidth })}
+ {...(noteUseTabs != null && { useTabs: noteUseTabs })}
+ {...(noteWrapLines != null && { lineWrapping: noteWrapLines })}
+ />
);
}
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index dc520a3c29..02fae231d7 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -3,20 +3,17 @@ import "./LinkEmbed.css";
import { CKTextEditor, EditorWatchdog, TemplateDefinition } from "@triliumnext/ckeditor5";
import { deferred } from "@triliumnext/commons";
-import { RefObject } from "preact";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import appContext from "../../../components/app_context";
-import { buildSelectedBackgroundColor } from "../../../components/touch_bar";
import dialog from "../../../services/dialog";
import { t } from "../../../services/i18n";
import link, { parseNavigationStateFromUrl } from "../../../services/link";
import note_create from "../../../services/note_create";
import options from "../../../services/options";
import toast from "../../../services/toast";
-import utils, { hasTouchBar, isMobile } from "../../../services/utils";
+import utils, { isMobile } from "../../../services/utils";
import { useEditorSpacedUpdate, useLegacyImperativeHandlers, useNoteLabel, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
-import TouchBar, { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl } from "../../react/TouchBar";
import { TypeWidgetProps } from "../type_widget";
import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog";
import getTemplates, { updateTemplateCache } from "./snippets.js";
@@ -34,7 +31,6 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
const contentRef = useRef<string>("");
const watchdogRef = useRef<EditorWatchdog>(null);
const editorApiRef = useRef<CKEditorApi>(null);
- const refreshTouchBarRef = useRef<() => void>(null);
const [ language ] = useNoteLabel(note, "language");
const [ textNoteEditorType ] = useTriliumOption("textNoteEditorType");
const [ codeBlockWordWrap ] = useTriliumOptionBool("codeBlockWordWrap");
@@ -279,13 +275,6 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
onWatchdogStateChange={onWatchdogStateChange}
onChange={() => spacedUpdate.scheduleUpdate()}
onEditorInitialized={(editor) => {
- if (hasTouchBar) {
- const handler = () => refreshTouchBarRef.current?.();
- for (const event of [ "bold", "italic", "underline", "paragraph", "heading" ]) {
- editor.commands.get(event)?.on("change", handler);
- }
- }
-
if (containerRef.current) {
setupImageOpening(containerRef.current, false);
}
@@ -298,8 +287,6 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
}}
/>}
-
- <EditableTextTouchBar watchdogRef={watchdogRef} refreshTouchBarRef={refreshTouchBarRef} />
</>
);
}
@@ -384,67 +371,3 @@ function onNotificationWarning(data, evt) {
evt.stop();
}
-function EditableTextTouchBar({ watchdogRef, refreshTouchBarRef }: { watchdogRef: RefObject<EditorWatchdog | null>, refreshTouchBarRef: RefObject<() => void> }) {
- const [ headingSelectedIndex, setHeadingSelectedIndex ] = useState<number>();
-
- function refresh() {
- let headingSelectedIndex: number | undefined;
- const editor = watchdogRef.current?.editor;
- const headingCommand = editor?.commands.get("heading");
- const paragraphCommand = editor?.commands.get("paragraph");
- if (paragraphCommand?.value) {
- headingSelectedIndex = 0;
- } else if (headingCommand?.value === "heading2") {
- headingSelectedIndex = 1;
- } else if (headingCommand?.value === "heading3") {
- headingSelectedIndex = 2;
- }
- setHeadingSelectedIndex(headingSelectedIndex);
- }
-
- useEffect(refresh, [ watchdogRef ]);
- refreshTouchBarRef.current = refresh;
-
- return (
- <TouchBar>
- <TouchBarSegmentedControl
- segments={[
- { label: "P" },
- { label: "H2" },
- { label: "H3" }
- ]}
- onChange={(selectedIndex) => {
- const editor = watchdogRef.current?.editor;
- switch (selectedIndex) {
- case 0:
- editor?.execute("paragraph");
- break;
- case 1:
- editor?.execute("heading", { value: "heading2" });
- break;
- case 2:
- editor?.execute("heading", { value: "heading3" });
- break;
- }
- }}
- selectedIndex={headingSelectedIndex}
- mode="buttons"
- />
-
- <TouchBarGroup>
- <TouchBarCommandButton watchdogRef={watchdogRef} command="bold" icon="NSTouchBarTextBoldTemplate" />
- <TouchBarCommandButton watchdogRef={watchdogRef} command="italic" icon="NSTouchBarTextItalicTemplate" />
- <TouchBarCommandButton watchdogRef={watchdogRef} command="underline" icon="NSTouchBarTextUnderlineTemplate" />
- </TouchBarGroup>
- </TouchBar>
- );
-}
-
-function TouchBarCommandButton({ watchdogRef, icon, command }: { watchdogRef: RefObject<EditorWatchdog | null>, icon: string, command: string }) {
- const editor = watchdogRef.current?.editor;
- return (<TouchBarButton
- icon={icon}
- click={() => editor?.execute(command)}
- backgroundColor={buildSelectedBackgroundColor(editor?.commands.get(command)?.value as boolean)}
- />);
-}
diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx
index b5defb99e3..b27ed58f4d 100644
--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx
@@ -17,7 +17,6 @@ import { renderMathInElement } from "../../../services/math";
import { formatCodeBlocks } from "../../../services/syntax_highlight";
import { useNoteBlob, useNoteLabel, useSyncedRef, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
import { RawHtmlBlock } from "../../react/RawHtml";
-import TouchBar, { TouchBarButton, TouchBarSpacer } from "../../react/TouchBar";
import { TypeWidgetProps } from "../type_widget";
import { applyReferenceLinks } from "./read_only_helper";
import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./utils";
@@ -45,19 +44,6 @@ export default function ReadOnlyText({ note, noteContext, ntxId }: TypeWidgetPro
dir={isRtl ? "rtl" : "ltr"}
contentRef={readOnlyContentRef}
/>
-
- <TouchBar>
- <TouchBarSpacer size="flexible" />
- <TouchBarButton
- icon="NSLockUnlockedTemplate"
- click={() => {
- if (noteContext?.viewScope) {
- noteContext.viewScope.readOnlyTemporarilyDisabled = true;
- appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
- }
- }}
- />
- </TouchBar>
</>
);
}