Spaces:
Running
Running
Import Monaco once. Suppress Ctrl-S. Use Router Links.
Browse files
lynxkite-app/web/src/Code.tsx
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
import Editor, { type Monaco } from "@monaco-editor/react";
|
4 |
import type { editor } from "monaco-editor";
|
5 |
import { useEffect, useRef } from "react";
|
6 |
-
import { useParams } from "react-router";
|
7 |
import { WebsocketProvider } from "y-websocket";
|
8 |
import * as Y from "yjs";
|
9 |
// @ts-ignore
|
@@ -22,9 +22,12 @@ export default function Code() {
|
|
22 |
const wsProviderRef = useRef<any>();
|
23 |
const monacoBindingRef = useRef<any>();
|
24 |
const yMonacoRef = useRef<any>();
|
|
|
25 |
const editorRef = useRef<any>();
|
26 |
useEffect(() => {
|
27 |
const loadMonaco = async () => {
|
|
|
|
|
28 |
// y-monaco is gigantic. The other Monaco packages are small.
|
29 |
yMonacoRef.current = await import("y-monaco");
|
30 |
initCRDT();
|
@@ -34,7 +37,9 @@ export default function Code() {
|
|
34 |
function beforeMount(monaco: Monaco) {
|
35 |
monaco.editor.defineTheme("lynxkite", theme);
|
36 |
}
|
37 |
-
function onMount(_editor: editor.IStandaloneCodeEditor) {
|
|
|
|
|
38 |
editorRef.current = _editor;
|
39 |
initCRDT();
|
40 |
}
|
@@ -66,9 +71,9 @@ export default function Code() {
|
|
66 |
return (
|
67 |
<div className="workspace">
|
68 |
<div className="top-bar bg-neutral">
|
69 |
-
<
|
70 |
<img alt="" src={favicon} />
|
71 |
-
</
|
72 |
<div className="ws-name">{path}</div>
|
73 |
<div className="tools text-secondary">
|
74 |
<button className="btn btn-link">
|
@@ -77,9 +82,9 @@ export default function Code() {
|
|
77 |
<button className="btn btn-link">
|
78 |
<Backspace />
|
79 |
</button>
|
80 |
-
<
|
81 |
<Close />
|
82 |
-
</
|
83 |
</div>
|
84 |
</div>
|
85 |
<Editor
|
|
|
3 |
import Editor, { type Monaco } from "@monaco-editor/react";
|
4 |
import type { editor } from "monaco-editor";
|
5 |
import { useEffect, useRef } from "react";
|
6 |
+
import { Link, useParams } from "react-router";
|
7 |
import { WebsocketProvider } from "y-websocket";
|
8 |
import * as Y from "yjs";
|
9 |
// @ts-ignore
|
|
|
22 |
const wsProviderRef = useRef<any>();
|
23 |
const monacoBindingRef = useRef<any>();
|
24 |
const yMonacoRef = useRef<any>();
|
25 |
+
const yMonacoLoadingRef = useRef(false);
|
26 |
const editorRef = useRef<any>();
|
27 |
useEffect(() => {
|
28 |
const loadMonaco = async () => {
|
29 |
+
if (yMonacoLoadingRef.current) return;
|
30 |
+
yMonacoLoadingRef.current = true;
|
31 |
// y-monaco is gigantic. The other Monaco packages are small.
|
32 |
yMonacoRef.current = await import("y-monaco");
|
33 |
initCRDT();
|
|
|
37 |
function beforeMount(monaco: Monaco) {
|
38 |
monaco.editor.defineTheme("lynxkite", theme);
|
39 |
}
|
40 |
+
function onMount(_editor: editor.IStandaloneCodeEditor, monaco: Monaco) {
|
41 |
+
// Do nothing on Ctrl+S. We save after every keypress anyway.
|
42 |
+
_editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => {});
|
43 |
editorRef.current = _editor;
|
44 |
initCRDT();
|
45 |
}
|
|
|
71 |
return (
|
72 |
<div className="workspace">
|
73 |
<div className="top-bar bg-neutral">
|
74 |
+
<Link className="logo" to="">
|
75 |
<img alt="" src={favicon} />
|
76 |
+
</Link>
|
77 |
<div className="ws-name">{path}</div>
|
78 |
<div className="tools text-secondary">
|
79 |
<button className="btn btn-link">
|
|
|
82 |
<button className="btn btn-link">
|
83 |
<Backspace />
|
84 |
</button>
|
85 |
+
<Link to={`/dir/${parentDir}`} className="btn btn-link">
|
86 |
<Close />
|
87 |
+
</Link>
|
88 |
</div>
|
89 |
</div>
|
90 |
<Editor
|