From 9ff199ea96cad070fd7c8d07535dcf8722d4a1dd Mon Sep 17 00:00:00 2001 From: Karmaa Date: Thu, 6 Mar 2025 18:43:27 -0600 Subject: [PATCH] Final preparations for release. Fixed auto resizing bug when smaller terminal size. --- src/App.jsx | 9 +++++---- src/Terminal.jsx | 40 ++++++++++++++++++++++++---------------- src/Utils.jsx | 7 +++++++ src/index.css | 9 +++++++++ 4 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 src/Utils.jsx diff --git a/src/App.jsx b/src/App.jsx index 6459b95b..d204071b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,6 +6,7 @@ import { CssVarsProvider } from "@mui/joy"; import theme from "./theme"; import TabList from "./TabList.jsx"; import Launchpad from "./Launchpad.jsx"; +import { Debounce } from './Utils'; import TermixIcon from "./images/termix_icon.png"; import RocketIcon from './images/launchpad_rocket.png'; @@ -50,7 +51,7 @@ function App() { }, [splitTabIds, activeTab, terminals]); useEffect(() => { - const handleResize = () => { + const handleResize = Debounce(() => { terminals.forEach((terminal) => { if ( (terminal.id === activeTab || splitTabIds.includes(terminal.id)) && @@ -59,7 +60,7 @@ function App() { terminal.terminalRef.resizeTerminal(); } }); - }; + }, 100); window.addEventListener("resize", handleResize); @@ -97,7 +98,7 @@ function App() { setActiveTab(nextId); setNextId(nextId + 1); setIsAddHostHidden(true); - setForm({ name: "", ip: "", user: "", password: "", rsaKey: "", port: 22, authMethod: "password" }); + setForm({ name: "", ip: "", user: "", password: "", rsaKey: "", port: 22, authMethod: "Select Auth" }); } else { alert("Please fill out all fields."); } @@ -198,7 +199,7 @@ function App() { {/* Terminal Views */} -
+
{terminals.map((terminal) => (
{ if (!parentContainer || !isVisible) return; - // Force a reflow to ensure the container's dimensions are up-to-date void parentContainer.offsetHeight; - // Use a small delay to ensure the DOM has fully updated - setTimeout(() => { - const parentWidth = parentContainer.clientWidth; - const parentHeight = parentContainer.clientHeight; + const parentWidth = parentContainer.clientWidth; + const parentHeight = parentContainer.clientHeight - 16; - terminalContainer.style.width = `${parentWidth}px`; - terminalContainer.style.height = `${parentHeight}px`; + terminalContainer.style.width = `${parentWidth}px`; + terminalContainer.style.height = `${parentHeight}px`; - // Fit the terminal to the container - fitAddon.current.fit(); + fitAddon.current.fit(); - // Notify the backend of the new terminal size - if (socketRef.current && terminalInstance.current) { - const { cols, rows } = terminalInstance.current; - socketRef.current.emit("resize", { cols, rows }); - } - }, 10); // Small delay to ensure proper DOM updates + if (socketRef.current && terminalInstance.current) { + const { cols, rows } = terminalInstance.current; + socketRef.current.emit("resize", { cols, rows }); + } }; useImperativeHandle(ref, () => ({ @@ -61,7 +55,6 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => { }); terminalInstance.current.loadAddon(fitAddon.current); - terminalInstance.current.open(terminalRef.current); setTimeout(() => { @@ -119,6 +112,21 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => { } }, [isVisible]); + useEffect(() => { + const terminalContainer = terminalRef.current; + if (!terminalContainer) return; + + const observer = new ResizeObserver(() => { + resizeTerminal(); + }); + + observer.observe(terminalContainer); + + return () => { + observer.disconnect(); + }; + }, []); + return (
{ + let timeout; + return (...args) => { + clearTimeout(timeout); + timeout = setTimeout(() => func.apply(this, args), wait); + }; +}; \ No newline at end of file diff --git a/src/index.css b/src/index.css index 36290d4e..bd106716 100644 --- a/src/index.css +++ b/src/index.css @@ -7,4 +7,13 @@ height: 24px; background-color: #4a5568; margin: 0 8px; +} + +.terminal-container { + min-height: 0; +} + +.terminal-container > div { + flex: 1; + min-height: 0; } \ No newline at end of file