worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Picker preview width is fixed at startup, doesn't follow terminal resizes

Open disrupted opened this issue 2 weeks ago • 2 comments

The picker reads the terminal size once and passes skim an absolute preview width (right:{cols/2} in PreviewLayout::spec_for). If the terminal is resized after wt switch starts, the split stays at the old width.

I hit this in Rex, which opens the picker in a floating pane. The pane's pty starts at 80×24 and gets its real size a moment later, so depending on the race the preview ends up 40 columns wide next to a ~160-column list, instead of 50/50. Resizing a regular terminal window while the picker is open shows the same thing.

Using a percentage (right:50% / down:N%) would let skim keep the split on resize. The pre-rendered previews are sized from the same startup width, so they'd probably also need to be re-rendered when the size changes.

Workaround for now: wait for the pty to get its size before starting wt.

disrupted avatar Nov 14 '26 23:11 disrupted

I confirmed this in the code. I haven't opened a PR yet: a complete fix touches the picker's preview cache as well as the skim spec, and just changing the spec would trade one stale width for another.

Two things in the picker are fixed at the startup width:

  • The window spec. spec_for asks skim for right:{cols/2}, which is an absolute column count. skim 5.9 already handles a resize: its Event::Resize arm recomputes the layout and runs the preview again (src/tui/app.rs around line 772), and Size::Percent maps to a ratatui Constraint::Percentage. So with right:50% skim would keep the split itself.
  • The rendered panes. The in-memory preview cache is keyed by (PickerRowId, PreviewMode) with no width (items.rs:154). preview_for_mode returns the cached body whatever context.width skim passes, and the pr pane is cached the same way. After a resize, skim calls the preview again at the new width, but it gets back text wrapped for the old width. In your Rex case that's a pane rendered for about 39 columns sitting inside an 80-column window. The on-disk diff and log caches already include width in their key, so the in-memory layer is the only part that ignores it.

So the durable fix is likely right:50% plus width in the in-memory cache key. With that, a resize misses the cache, and the existing demand path (local.demand.request with skim's context.width) recomputes the pane at the new size. Two details still need deciding:

  • Rounding. dimensions_for floors 50% and subtracts the one column skim leaves unpainted. ratatui's percentage solver needs to land on the same width at odd column counts, or the last column gets dropped again.
  • Down layout. Its band height is computed from the estimated row count, so it can't just become a percentage. It also isn't the symptom you reported.

Waiting for the pty size before starting wt, as you're doing now, is the right workaround until this lands.

worktrunk-bot avatar Nov 14 '26 23:11 worktrunk-bot

I could reproduce the split part of this in a PTY test, but I don't have a fix I can defend yet. #4794 adds the test: it opens the picker at 120 columns, resizes to 200, and the separator stays at column 140 on main.

Switching to right:50% makes that test pass, and skim then keeps the split on resize. It also introduces two problems:

  • skim's pane geometry changes. With a percentage, the startup pane is one column narrower than the width the picker renders for, so the last column of the preview is cut off. Three existing picker snapshots fail on that. The preview text width needs re-deriving for the percentage layout before this can ship.
  • skim reports the old width right after a resize. skim 5.9 re-runs the preview before it updates the pane width. That means preview() still sees the startup width until the next keystroke, which reports the new one. Even with width added to the in-memory cache key, the pane body would only re-render on the next keystroke. Re-rendering at the moment of the resize would need a change in skim.

The measurements are in the PR description. Waiting for the pty size before launching wt is still the reliable workaround.

worktrunk-bot avatar Nov 14 '26 23:11 worktrunk-bot