From 0dcaa8719fd898cc6e87cff821412d34adccaab7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 5 Oct 2025 17:56:20 +0300 Subject: [PATCH] chore(react/type_widgets): save code note if needed --- apps/client/src/components/entrypoints.ts | 1 + apps/client/src/widgets/note_detail.ts.bak | 9 --------- .../client/src/widgets/type_widgets/code/Code.tsx | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/client/src/components/entrypoints.ts b/apps/client/src/components/entrypoints.ts index 7989960a6..91895d77f 100644 --- a/apps/client/src/components/entrypoints.ts +++ b/apps/client/src/components/entrypoints.ts @@ -165,6 +165,7 @@ export default class Entrypoints extends Component { return; } const { ntxId, note } = noteContext; + console.log("Run active note"); // ctrl+enter is also used elsewhere, so make sure we're running only when appropriate if (!note || note.type !== "code") { diff --git a/apps/client/src/widgets/note_detail.ts.bak b/apps/client/src/widgets/note_detail.ts.bak index 993181547..542c40dc2 100644 --- a/apps/client/src/widgets/note_detail.ts.bak +++ b/apps/client/src/widgets/note_detail.ts.bak @@ -12,15 +12,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { appContext.addBeforeUnloadListener(this); } - - async runActiveNoteCommand(params: CommandListenerData<"runActiveNote">) { - if (this.isNoteContext(params.ntxId)) { - // make sure that script is saved before running it #4028 - await this.spacedUpdate.updateNowIfNecessary(); - } - - return await this.parent?.triggerCommand("runActiveNote", params); - } beforeUnloadEvent() { return this.spacedUpdate.isAllSavedAndTriggerUpdate(); diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx index e65445a44..0cbba25ea 100644 --- a/apps/client/src/widgets/type_widgets/code/Code.tsx +++ b/apps/client/src/widgets/type_widgets/code/Code.tsx @@ -4,9 +4,9 @@ import { TypeWidgetProps } from "../type_widget"; import "./code.css"; import CodeMirror, { CodeMirrorProps } from "./CodeMirror"; import utils from "../../../services/utils"; -import { useEditorSpacedUpdate, useKeyboardShortcuts, useNoteBlob, useSyncedRef, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks"; +import { useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteBlob, useSyncedRef, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks"; import { t } from "../../../services/i18n"; -import appContext from "../../../components/app_context"; +import appContext, { CommandListenerData } from "../../../components/app_context"; import TouchBar, { TouchBarButton } from "../../react/TouchBar"; import { refToJQuerySelector } from "../../react/react_utils"; import { CODE_THEME_DEFAULT_PREFIX as DEFAULT_PREFIX } from "../constants"; @@ -89,6 +89,17 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC updateInterval }); + // make sure that script is saved before running it #4028 + useLegacyImperativeHandlers({ + async runActiveNoteCommand(params: CommandListenerData<"runActiveNote">) { + if (params.ntxId === ntxId) { + await spacedUpdate.updateNowIfNecessary(); + } + + return await parentComponent?.parent?.triggerCommand("runActiveNote", params); + } + }); + useKeyboardShortcuts("code-detail", containerRef, parentComponent); return (