huh icon indicating copy to clipboard operation
huh copied to clipboard

Option with \n in it breaks scrolling with NewSelect, probably others

Open iloveicedgreentea opened this issue 3 months ago • 0 comments

Describe the bug

var controlIDs []huh.Option[string]

for k, v := range m.appState.ControlIDs {
	x := huh.NewOption(fmt.Sprintf("%s \n %s", k, v), fmt.Sprintf("%s \n %s", k, v))
controlIDs = append(controlIDs, x)
}

huh.NewGroup(
	huh.NewSelect[string]().
		Key(keyControlIDs).
		// build control IDs based on type
		Options(controlIDs...).
		Title("Choose your control ID").
		Description("Placeholder").
		Value(&selectedControl),
),

The above code will generate an item that is formatted correctly however if the view height is < max items, scrolling will break. That means instead of the focused item being highlighted as you scroll, it will scroll past your view and scroll off screen. I suspect the View function responsible for calculating the height of all items does not account for \n in each item

Removing the \n immediately fixes the problem. However I don't think its \n per se, its really just any item that is two lines long as it happens for very long strings too (string > max width)

To Reproduce Steps to reproduce the behavior: Use the above code to create a form with new lines in it or ones that are really long

Expected behavior I expect scrolling to not get cut off and work as expected, based on where the cursor is

iloveicedgreentea avatar Apr 10 '24 01:04 iloveicedgreentea