Repaint sidebar after child scrolls the host scroll region
Codex (Ratatui) emits an 8x RI burst on startup right after setting DECSTBM. RI at the top of the scroll region scrolls the region down, and DECSTBM only constrains rows -- so the scroll spans every column and drags the right-rail session-tree entries down with the main pane. The chrome cache then hid the clobber because the computed sidebar frame was unchanged. The viewport renderer now flags any chunk containing RI / IND / NEL / SU / SD / IL / DL and OnPTYOut drops the sidebar cache when the flag is set, so the next drawSidebar repaints over the drift. Adds unit tests for the new flag and a harness regression scenario (sidebar_survives_ri_scroll) that fails without the fix.
This commit is contained in:
@@ -19,6 +19,14 @@ type viewportRenderer struct {
|
||||
state viewportState
|
||||
buf []byte
|
||||
pending strings.Builder
|
||||
|
||||
// scrolled is set when the chunk contained an escape that shifts
|
||||
// content row-wise within the host's scroll region — RI / IND /
|
||||
// NEL / SU / SD / IL / DL. DECSTBM constrains rows but not columns,
|
||||
// so these scrolls drag the right-hand sidebar content with them.
|
||||
// OnPTYOut consumes the flag and invalidates the sidebar chrome
|
||||
// cache so the next drawSidebar repaints over the clobber.
|
||||
scrolled bool
|
||||
}
|
||||
|
||||
type viewportState int
|
||||
@@ -67,6 +75,20 @@ func (vr *viewportRenderer) ClearViewport() []byte {
|
||||
return []byte(vr.clearViewport())
|
||||
}
|
||||
|
||||
// TookScrollAction reports whether the most recent Render emitted (or
|
||||
// forwarded) a scroll-triggering escape — RI / IND / NEL / SU / SD /
|
||||
// IL / DL — since the previous call. The flag is reset on read.
|
||||
// Callers use it to invalidate sidebar-cache state, because the host's
|
||||
// scroll region spans the full row width and any scroll there drags
|
||||
// the sidebar content downward.
|
||||
func (vr *viewportRenderer) TookScrollAction() bool {
|
||||
vr.mu.Lock()
|
||||
defer vr.mu.Unlock()
|
||||
out := vr.scrolled
|
||||
vr.scrolled = false
|
||||
return out
|
||||
}
|
||||
|
||||
func (vr *viewportRenderer) feed(b byte) {
|
||||
switch vr.state {
|
||||
case vpNormal:
|
||||
@@ -89,6 +111,18 @@ func (vr *viewportRenderer) feed(b byte) {
|
||||
vr.state = vpDCS
|
||||
case 'X', '^', '_':
|
||||
vr.state = vpSOSPMAPC
|
||||
case 'M', 'D', 'E':
|
||||
// RI (ESC M), IND (ESC D), NEL (ESC E). All three can scroll
|
||||
// the host's scroll region when the cursor is at the top
|
||||
// (RI) or bottom (IND/NEL) edge. The region spans the full
|
||||
// row width, so the scroll drags the sidebar columns along
|
||||
// with the main pane. Forward as-is and flag for sidebar
|
||||
// cache invalidation. Codex emits 8× RI on startup, which
|
||||
// is what motivated this branch.
|
||||
vr.pending.Write(vr.buf)
|
||||
vr.scrolled = true
|
||||
vr.state = vpNormal
|
||||
vr.buf = vr.buf[:0]
|
||||
default:
|
||||
vr.pending.Write(vr.buf)
|
||||
vr.state = vpNormal
|
||||
@@ -177,6 +211,15 @@ func (vr *viewportRenderer) emitCSI() {
|
||||
return
|
||||
}
|
||||
vr.pending.WriteString(vr.clearLine(n))
|
||||
case 'S', 'T', 'L', 'M':
|
||||
// SU (S) / SD (T) / IL (L) / DL (M) all shift content within
|
||||
// the host's scroll region row-wise across every column. The
|
||||
// sidebar lives at the right of the host, inside the scroll
|
||||
// region's row range, so any of these drag its cells along
|
||||
// with the main pane. Forward verbatim and flag the chunk so
|
||||
// the sidebar is repainted afterwards.
|
||||
vr.pending.Write(vr.shifter.Shift(vr.buf))
|
||||
vr.scrolled = true
|
||||
default:
|
||||
vr.pending.Write(vr.shifter.Shift(vr.buf))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user