From 6b60e02ba1507fa371ea301d35b0714aa5beac87 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Sat, 3 Feb 2024 00:49:12 +0100 Subject: [PATCH] removed old code saving is now entirely done through the editors command api --- src/ui/src/components/Editor.js | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/ui/src/components/Editor.js b/src/ui/src/components/Editor.js index 5f48ed6..0eb53fa 100644 --- a/src/ui/src/components/Editor.js +++ b/src/ui/src/components/Editor.js @@ -1,35 +1,15 @@ -import React, {useEffect, useContext, useRef} from "react"; +import React from "react"; import Monaco from "@monaco-editor/react"; -import SlideContext from "../shared/SlideContext"; -import Mode from "../models/Mode"; - const Editor = ({show, source}) => { - const editor = useRef(); - const {mode} = useContext(SlideContext); - - useEffect(() => { - const listener = event => { - if (!event.metaKey && !event.ctrlKey) - return; - if (mode !== Mode.EDIT || event.key !== "s") - return; - - window.api.saveFile(editor.current?.getValue()); - }; - - document.addEventListener("keydown", listener); - - return () => { - document.removeEventListener("keydown", listener); - }; - }, [mode]); const editorMount = (instance, monaco) => { + // NOTE: I have no idea, why we have to re-add these ourselves, but this + // code works, so be it. --MikO instance.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyC, () => instance.trigger("source","editor.action.clipboardCopyAction")); instance.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyV, () => instance.trigger("source","editor.action.clipboardPasteAction")); instance.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyX, () => instance.trigger("source","editor.action.clipboardCutAction")); - editor.current = instance; + instance.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => window.api.saveFile(instance.getValue())); } if (!show)