charmbracelet / huh

Build terminal forms and prompts 🤷🏻‍♀️
MIT License
4.39k stars 126 forks source link

Select options disappear when other options wrap #429

Open seeseemelk opened 1 month ago

seeseemelk commented 1 month ago

Describe the bug When showing a Select menu, the last option disappears when at least two options have to wrap

To Reproduce Steps to reproduce the behavior:

  1. Create a select with at least three (long) options
  2. Make your terminal small enough so that two options have to wrap
  3. See the last one disappear

Expected behavior All possible options should stay visible.

Screenshots No wrapping, all options are visible: Screenshot_2024-10-18_07-51-19

One option wraps, all options are visible: Screenshot_2024-10-18_07-51-29

Two options wrap, the last option disappears: Screenshot_2024-10-18_07-51-42

Desktop (please complete the following information):

seeseemelk commented 3 weeks ago

I've been looking into this a little: the select option hard-codes that it should scroll down a single line when pressing the down arrow key. Changing this to, say, 2, helps a little, but does not actually fix it.

The Viewport class itself also seems to assume that lines don't wrap. It generates a slice of visible lines based on the viewport height and scroll position, but this slice does not take wrapping into account.

Likely, if the Viewport is modified so it correctly considers wrapping, the Select will probably just work

bashbunni commented 3 weeks ago

I agree this is likely viewport not calculating height properly

Kyren223 commented 3 weeks ago

@bashbunni It is, I independently also discovered it, there is an open issue at bubbles https://github.com/charmbracelet/bubbles/issues/644