Replies: 1 comment 1 reply
-
|
Hello, This is the default behavior of xterm.js when calling fit() on resize. When the height grows, xterm adds empty rows below the cursor (the buffer grows downward), so your prompt stays where it was and looks like it's being pushed down — until the next render snaps it back into place. I solved a similar problem doing this: const handleResize = () => {
const t = termRef.current;
if (!t) return;
t.fitAddon.fit();
t.term.scrollToBottom();
};And the same on the initial fit requestAnimationFrame(() => {
fitAddon.fit();
term.scrollToBottom();
});Using window.resize (it fires on window changes, not on containers changes) and is expensive because it fires a lot. I had a lot of problems so I change it using ResizeObserver let rafId = 0;
const ro = new ResizeObserver(() => {
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
fitAddon.fit();
term.scrollToBottom();
});
});
ro.observe(containerRef.current);
// cleanup
return () => {
ro.disconnect();
cancelAnimationFrame(rafId);
term.dispose();
};Hope it helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently I have an XTerm setup like this:
When resizing, I noticed the prompt input field always got pushed down a bit before resizing again...

But in VSCode, I don't see that behavior...

Is anyone know how do I archive the behavior like the terminal in VSCode?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions