mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #1023] Add ability to select list item programatically #741
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#741
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SamWhited on GitHub (Sep 12, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1023
Right now in an application I have a list of items. Some of the items can be selected with a keyboard shortcut other than
KeyCR(let's say '1' selects the first item, for the sake of this example). Right now to select the item I have to do something like this (in anInputHandler()implementation, for the sake of this example, but if you were usingSetInputHandleryou'd have to return the fake event and it's broadly similar):It would be nice to have a way to either get the "selected" function from the current list item, or a function to select an item just as if enter were pressed without having to manually trigger a keyboard event. This would make the example much easier to read:
I'm happy to implement this if you like the API and need a hand.
EDIT: realized this is a bad example because if it were just '1' you could use the shortcut rune, but in my actual case it's a more complicated key combo and this won't work. Anyways, keep in mind that it's just an example.
Also, went ahead and made a PR just to make it easy to see what the change would be like. Happy to change the API or close it if it doesn't get accepted, of course.
@rivo commented on GitHub (Nov 3, 2024):
The latest commit adds
GetSelectedFuncandGetItemSelectedFunctoList. I'm not a fan of invoking the callbacks in a separate function but it's ok to get out what you put in.