Replies: 2 comments 7 replies
-
|
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.
-
|
If the cursor is on the bottom row before resize, it probably makes sense for it to stay on the bottom row after resize (assuming there are enough lines available in the scrollback). However, it does have the unusual effect that the "home" position might move backwards into the scrollback area. |
Beta Was this translation helpful? Give feedback.

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