removed old code

saving is now entirely done through the editors command api
master
Michael Ochmann 1 year ago
parent 6461d432f2
commit 6b60e02ba1
  1. 28
      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)

Loading…
Cancel
Save