fix(dashboard): let embedded chat use a single scroll system

This commit is contained in:
nouseman666 2026-05-03 22:09:37 +08:00 committed by Teknium
parent a0758cd1e9
commit 8aceef539f

View file

@ -260,11 +260,10 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
fontWeight: "400", fontWeight: "400",
fontWeightBold: "700", fontWeightBold: "700",
macOptionIsMeta: true, macOptionIsMeta: true,
// Keep a reasonable terminal history in the browser so users can // Single-scroll-system experiment:
// scroll back through earlier conversation/tool output. A zero // let the inner Hermes TUI own transcript history/scroll behavior.
// scrollback makes wheel scrolling feel broken once the visible // The outer browser xterm should act as a display/input bridge only.
// viewport fills. scrollback: 0,
scrollback: 5000,
theme: TERMINAL_THEME, theme: TERMINAL_THEME,
}); });
termRef.current = term; termRef.current = term;
@ -367,25 +366,6 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
fitRef.current = fit; fitRef.current = fit;
term.loadAddon(fit); term.loadAddon(fit);
// Force a browser-native-feeling wheel path for the embedded chat.
// The default xterm.js / terminal-app interaction can be ambiguous in
// our PTY setup: wheel events may be interpreted as terminal mouse
// input, ignored by the app, or otherwise fail to move the browser-side
// scrollback even when history exists. Intercept the wheel gesture at
// the terminal boundary and map it directly onto xterm's own scrollback.
term.attachCustomWheelEventHandler((ev) => {
const delta = ev.deltaY;
if (!delta) {
return false;
}
const step = Math.max(1, Math.round(Math.abs(delta) / 40));
term.scrollLines(delta > 0 ? step : -step);
ev.preventDefault();
ev.stopPropagation();
return false;
});
const unicode11 = new Unicode11Addon(); const unicode11 = new Unicode11Addon();
term.loadAddon(unicode11); term.loadAddon(unicode11);
term.unicode.activeVersion = "11"; term.unicode.activeVersion = "11";
@ -492,7 +472,6 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
window.addEventListener("resize", scheduleSyncTerminalMetrics); window.addEventListener("resize", scheduleSyncTerminalMetrics);
window.visualViewport?.addEventListener("resize", scheduleSyncTerminalMetrics); window.visualViewport?.addEventListener("resize", scheduleSyncTerminalMetrics);
window.visualViewport?.addEventListener("scroll", scheduleSyncTerminalMetrics);
scheduleHostSync(); scheduleHostSync();
requestAnimationFrame(() => scheduleHostSync()); requestAnimationFrame(() => scheduleHostSync());
@ -604,10 +583,6 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
"resize", "resize",
scheduleSyncTerminalMetrics, scheduleSyncTerminalMetrics,
); );
window.visualViewport?.removeEventListener(
"scroll",
scheduleSyncTerminalMetrics,
);
ro.disconnect(); ro.disconnect();
if (hostSyncRaf) cancelAnimationFrame(hostSyncRaf); if (hostSyncRaf) cancelAnimationFrame(hostSyncRaf);
if (settleRaf1) cancelAnimationFrame(settleRaf1); if (settleRaf1) cancelAnimationFrame(settleRaf1);