fix(web): keep the reader's row when a flush clears scrollback (#814)

- flushPendingWrites falls back to the absolute viewport index when the write disposed the marker, which ESC[3J or RIS also do (the narrow and middle strips keep 3J), instead of sending the reader to row 0.
- The live-output mark block moves below the write's try/catch, so the catch only covers the write.
- Test: one flush of ESC[H ESC[2J ESC[3J plus a reprint keeps the reader on line 100, with and without markers.
This commit is contained in:
Hadrien Kerlero committed 2026-11-23 15:22:07 +01:00
1 parent a92d512459
commit e44d586f93
3 files changed
+43 -14

No files matched your search

+26
View File
@@ -102,4 +102,30 @@ describe('live terminal viewport at the scrollback cap', () => {
expect(row).not.toBe('line 140');
expect(row).toBe('line 160');
});
// ESC[3J (kept by the narrow and middle strips) erases scrollback and disposes
// the marker the same way a trim does; the reader must keep their row, not
// land on row 0.
it.each([true, false])(
'keeps the reader on their row when one flush clears scrollback and reprints it (markers: %s)',
async (markersEnabled) => {
const terminal = new Terminal({ cols: 80, rows: 10, scrollback: 1000, allowProposedApi: true });
try {
if (!markersEnabled) Object.defineProperty(terminal, 'registerMarker', { value: undefined });
const app = loadHarness(terminal);
const history = Array.from({ length: 200 }, (_, i) => `line ${i}\r\n`).join('');
await write(terminal, history);
terminal.scrollToLine(100);
expect(topRow(terminal)).toBe('line 100');
expect(app.isTerminalAtBottom()).toBe(false);
app.pendingWrites.push(`\x1b[H\x1b[2J\x1b[3J${history}`);
app.flushPendingWrites();
await write(terminal, '');
expect(app._terminalWriteInFlight).toBe(false);
expect(topRow(terminal)).toBe('line 100');
} finally {
terminal.dispose();
}
}
);
});