Clear stale terminal selection during pane recovery (#13677)

* fix(terminal): forward copy to TUI selections

* fix(terminal): narrow recovery selection cleanup
This commit is contained in:
Brennan Benson
2026-08-10 15:52:25 -07:00
committed by GitHub
parent 84bd306949
commit fb80f91921
2 changed files with 21 additions and 0 deletions
@@ -527,6 +527,12 @@ describe('openTerminal — addon and provider wiring', () => {
deregisterCharacterJoiner: vi.fn((joinerId: number) => {
events.push(`deregisterCharacterJoiner:${joinerId}`)
}),
clearSelection: vi.fn(() => {
events.push('clearSelection')
}),
dispose: vi.fn(() => {
events.push('dispose')
}),
unicode: unicodeProxy,
buffer: { active: { cursorX: 0, cursorY: 0 } }
} as unknown as ManagedPaneInternal['terminal']
@@ -607,6 +613,15 @@ describe('openTerminal — addon and provider wiring', () => {
expect(pane.arabicShapingJoinerCleanup).toBeNull()
})
it('clears selection before disposing a remounted pane', () => {
const { pane, events } = createOpenTerminalHarness()
openTerminal(pane)
disposePane(pane, new Map([[pane.id, pane]]))
expect(events.indexOf('clearSelection')).toBeLessThan(events.indexOf('dispose'))
})
// Why: a link streamed under a stationary pointer must re-linkify on the next
// move; openTerminal wires the hover-cache reset and disposePane must detach it.
it('installs the streamed-output linkifier hover reset and disposes it', () => {
@@ -254,6 +254,12 @@ export function disposePane(
} catch {
/* ignore */
}
try {
// Drop renderer selection state before a recovery remount replaces the surface.
pane.terminal.clearSelection()
} catch {
/* ignore */
}
try {
pane.terminal.dispose()
} catch {