xtermjs / xterm.js

A terminal for the web
https://xtermjs.org/
MIT License
17.04k stars 1.6k forks source link

SearchAddon matches fall out of sync on some multiline inputs when over the scrollback limit. #4994

Closed tabarra closed 4 months ago

tabarra commented 4 months ago

If you have a search and your buffer is already at the scrollback limit (so that older lines are dropped), any multi-line term.write() and any term.writeln() ending in \n causes the march decorations to fall out of sync with the buffer and mark the wrong lines.
Video:

https://github.com/xtermjs/xterm.js/assets/1808295/2eee11b3-6b75-4002-bb67-0ae2b68ae078

Details

Versions:

"xterm": "5.4.0-beta.20",
"xterm-addon-search": "0.14.0-beta.20"

Repro sandbox: https://codesandbox.io/p/sandbox/xtermjs-demo-forked-2jpjsz It looks like every multi-line .write() will cause this bug, and only the .writeln() that ends with new lines.
In the sandbox I provided a bunch of example combinations where it breaks or doesn't.
This only works when the buffer is already at the scrollback limit, so I changed the options to have 0 scrollback to facilitate testing.

Tyriar commented 4 months ago

Simple demo repro:

  1. Set scrollback to 1
  2. Run ls (fill scrollback)
  3. Search for something
  4. Press enter in terminal

image