Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

test(terminal): pin the trim with a wide character on the new edge; note why only the alt buffer

Erik Zwep26ead9f1078d
diff --git a/src/renderer/terminal/shrink-trim.test.ts b/src/renderer/terminal/shrink-trim.test.ts
index f460608a2..64727ef1d 100644
--- a/src/renderer/terminal/shrink-trim.test.ts
+++ b/src/renderer/terminal/shrink-trim.test.ts
@@ -104,6 +104,17 @@ describe('patchShrinkTrim', () => {
expect(term.buffer.active.getLine(0)!.translateToString(true)).toBe('x'.repeat(100))
})
+ it('a wide character cut by the new edge does not break the trim or the find', async () => {
+ const { term, search } = open(130)
+ patchShrinkTrim(term)
+ // '日' is two cells wide and lands on columns 99–100: the narrowing to 100 cuts through it.
+ await write(term, ALT_SCREEN + 'x'.repeat(99) + '日 s')
+ term.resize(100, 5)
+ expect(() => find(search, 's')).not.toThrow()
+ expect(find(search, '日')).toBe(1)
+ expect(term.buffer.active.getLine(0)!.length).toBe(100)
+ })
+
it('is idempotent and fails open on a terminal without the expected internals', async () => {
const { term, search } = open(130)
expect(patchShrinkTrim(term)).toBe(true)
diff --git a/src/renderer/terminal/shrink-trim.ts b/src/renderer/terminal/shrink-trim.ts
index bcda7dc20..80baa3bfa 100644
--- a/src/renderer/terminal/shrink-trim.ts
+++ b/src/renderer/terminal/shrink-trim.ts
@@ -69,7 +69,9 @@ export function patchShrinkTrim(term: Terminal): boolean {
if (!narrowed) return
try {
// Only the alternate buffer: the normal one reflows whenever it has scrollback, which
- // xterm trims itself, and walking up to 50k scrollback lines per resize would be waste.
+ // xterm trims itself. Our terminals never set `scrollback: 0` or `windowsPty` (the two
+ // things that turn reflow off), so walking the normal buffer here would only be waste.
+ // `onResize` fires synchronously right after `buffers.resize`, before any render.
trimBuffer(core.buffers?.alt, next)
} catch {
// Fail open: an untrimmed line is the stock behavior, never worse.