mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 09:15:50 +01:00
chore(react/type_widgets): save code note if needed
This commit is contained in:
@@ -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") {
|
||||
|
||||
@@ -13,15 +13,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();
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user