Merge branch 'dev' of ssh://git.commumedia.org:2222/alex/headquarter into dev
This commit is contained in:
@@ -216,36 +216,17 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
|
||||
// Fit terminal and notify backend
|
||||
const fitTerminal = () => {
|
||||
if (!fitAddonRef.current || !termRef.current) {
|
||||
console.log('[Terminal] fitTerminal: refs not ready');
|
||||
return;
|
||||
}
|
||||
if (!fitAddonRef.current || !termRef.current) return;
|
||||
const oldCols = termRef.current.cols;
|
||||
const oldRows = termRef.current.rows;
|
||||
|
||||
console.log('[Terminal] fitTerminal called, container dims:', container?.offsetWidth, container?.offsetHeight);
|
||||
|
||||
fitAddonRef.current.fit();
|
||||
const { cols, rows } = termRef.current;
|
||||
console.log('[Terminal] fitTerminal result:', cols, rows, '(was:', oldCols, oldRows + ')');
|
||||
|
||||
// Force explicit resize to ensure xterm.js updates its canvas
|
||||
// Force refresh if dimensions changed
|
||||
if (cols !== oldCols || rows !== oldRows) {
|
||||
termRef.current.resize(cols, rows);
|
||||
termRef.current.refresh(0, rows - 1);
|
||||
}
|
||||
|
||||
// Always refresh on initial load or when dimensions change
|
||||
requestAnimationFrame(() => {
|
||||
if (termRef.current) {
|
||||
termRef.current.refresh(0, termRef.current.rows - 1);
|
||||
}
|
||||
});
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
console.log('[Terminal] Sending resize:', cols, rows);
|
||||
ws.send(JSON.stringify({ type: "resize", cols, rows }));
|
||||
} else {
|
||||
console.log('[Terminal] WebSocket not open, state:', ws.readyState);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -261,14 +242,6 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
requestAnimationFrame(() => fitTerminal());
|
||||
});
|
||||
|
||||
// Delayed refit after WebSocket connects to ensure backend is synced
|
||||
const delayedFitTimeout = setTimeout(() => {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
console.log('[Terminal] Delayed refit after WebSocket connect');
|
||||
fitTerminal();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// Handle terminal input
|
||||
term.onData((data) => {
|
||||
if (ws.readyState !== WebSocket.OPEN) return;
|
||||
@@ -311,19 +284,6 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
});
|
||||
resizeObserver.observe(container);
|
||||
|
||||
// Also listen for window resize as fallback (ResizeObserver might miss some cases)
|
||||
let windowResizeTimeout: ReturnType<typeof setTimeout>;
|
||||
const handleWindowResize = () => {
|
||||
clearTimeout(windowResizeTimeout);
|
||||
windowResizeTimeout = setTimeout(() => {
|
||||
requestAnimationFrame(() => {
|
||||
if (!container.isConnected) return;
|
||||
fitTerminal();
|
||||
});
|
||||
}, 250);
|
||||
};
|
||||
window.addEventListener("resize", handleWindowResize);
|
||||
|
||||
// Refit after mobile header auto-hides (3s delay + 0.3s transition)
|
||||
const headerHideTimeout = setTimeout(() => {
|
||||
fitTerminal();
|
||||
@@ -356,11 +316,8 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
|
||||
return () => {
|
||||
clearTimeout(resizeTimeout);
|
||||
clearTimeout(windowResizeTimeout);
|
||||
clearTimeout(headerHideTimeout);
|
||||
clearTimeout(delayedFitTimeout);
|
||||
resizeObserver.disconnect();
|
||||
window.removeEventListener("resize", handleWindowResize);
|
||||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||
if (ws) {
|
||||
ws.close();
|
||||
|
||||
Reference in New Issue
Block a user