Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widgets): save code note if needed

Elian Doran0dcaa8719fd8
diff --git a/apps/client/src/components/entrypoints.ts b/apps/client/src/components/entrypoints.ts
index 7989960a6b..91895d77f3 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 993181547d..542c40dc27 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 e65445a44e..0cbba25ea9 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 (