From 07c744b2ccbd0d511ca565a85dac4b277cca6baa Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:26:39 +0800 Subject: [PATCH] Update Terminal.vue --- packages/frontend/src/components/Terminal.vue | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/frontend/src/components/Terminal.vue b/packages/frontend/src/components/Terminal.vue index 6f66232..ca44eb8 100644 --- a/packages/frontend/src/components/Terminal.vue +++ b/packages/frontend/src/components/Terminal.vue @@ -110,11 +110,12 @@ onMounted(() => { const container = terminalRef.value; // 捕获引用 resizeObserver = new ResizeObserver((entries) => { const entry = entries[0]; - const { height } = entry.contentRect; - // console.log(`[Terminal ${props.sessionId}] ResizeObserver triggered. Height: ${height}, isActive: ${props.isActive}`); - if (height > 0 && terminal) { // 仅在可见时调整 + const { height, width } = entry.contentRect; // 获取宽度和高度 + // console.log(`[Terminal ${props.sessionId}] ResizeObserver triggered. Size: ${width}x${height}, isActive: ${props.isActive}`); + if (height > 0 && width > 0 && terminal) { // 确保宽度和高度都有效,并且终端实例存在 try { - // fitAddon?.fit(); // 视觉上适应 <-- 移除此行,不再强制 fit 内部行数 + // *** 新增:立即调用 fit() 来适应前端容器 *** + fitAddon?.fit(); // 触发防抖的 resize 发送,通知后端潜在的尺寸变化 debouncedEmitResize(terminal); } catch (e) { @@ -166,15 +167,7 @@ onMounted(() => { if (done) break; if (terminal && value) { terminal.write(value); // 将流数据写入终端 - // 尝试在写入数据后调用 fit,看是否能触发滚动条 - nextTick(() => { // 使用 nextTick 确保 DOM 更新后再 fit - try { - fitAddon?.fit(); - // 注意:这里可能不需要再 emit resize,因为 fit 主要是为了更新内部布局以适应外部滚动 - } catch (fitError) { - console.warn("Fit addon failed after writing stream data:", fitError); - } - }); + // 移除此处不必要的 fit() 调用 } } } catch (error) { @@ -266,15 +259,12 @@ defineExpose({ write });