diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 33ec58f..302670b 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -353,11 +353,11 @@ export default function CodeEditor({ socket.disconnect(); resizeObserver.disconnect(); - terminals.forEach((term) => { - if (term.terminal) { - term.terminal.dispose(); - } - }); + // terminals.forEach((term) => { + // if (term.terminal) { + // term.terminal.dispose(); + // } + // }); }; }, []); @@ -494,8 +494,8 @@ export default function CodeEditor({ : terminals[index - 1].id : activeTerminalId; - if (activeTerminal && activeTerminal.terminal) - activeTerminal.terminal.dispose(); + // if (activeTerminal && activeTerminal.terminal) + // activeTerminal.terminal.dispose(); setTerminals((prev) => prev.filter((t) => t.id !== term.id)); if (!nextId) { @@ -784,25 +784,29 @@ export default function CodeEditor({ {socket && activeTerminal ? (
- { - console.log( - "setting terminal", - activeTerminalId, - t.options - ); - setTerminals((prev) => - prev.map((term) => - term.id === activeTerminalId - ? { ...term, terminal: t } - : term - ) - ); - }} - /> + {terminals.map((term) => ( + { + // console.log( + // "setting terminal", + // activeTerminalId, + // t.options + // ); + setTerminals((prev) => + prev.map((term) => + term.id === activeTerminalId + ? { ...term, terminal: t } + : term + ) + ); + }} + visible={activeTerminalId === term.id} + /> + ))}
) : (
diff --git a/frontend/components/editor/terminal/index.tsx b/frontend/components/editor/terminal/index.tsx index f912dfd..8408764 100644 --- a/frontend/components/editor/terminal/index.tsx +++ b/frontend/components/editor/terminal/index.tsx @@ -13,19 +13,19 @@ export default function EditorTerminal({ id, term, setTerm, + visible, }: { socket: Socket; id: string; term: Terminal | null; setTerm: (term: Terminal) => void; + visible: boolean; }) { const terminalRef = useRef(null); useEffect(() => { if (!terminalRef.current) return; - console.log("new terminal", id, term ? "reusing" : "creating"); - - if (term) return; + // console.log("new terminal", id, term ? "reusing" : "creating"); const terminal = new Terminal({ cursorBlink: true, @@ -40,22 +40,19 @@ export default function EditorTerminal({ setTerm(terminal); - // return () => { - // if (terminal) terminal.dispose(); - // }; - }, [id]); + return () => { + if (terminal) terminal.dispose(); + }; + }, []); useEffect(() => { if (!term) return; - console.log("A"); if (terminalRef.current) { const fitAddon = new FitAddon(); term.loadAddon(fitAddon); term.open(terminalRef.current); - console.log("B"); fitAddon.fit(); - // setTerm(term); } const disposable = term.onData((data) => { console.log("terminalData", id, data); @@ -69,7 +66,11 @@ export default function EditorTerminal({ return ( <> -
+
{term === null ? (