mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #776] Handling keys in InputField -> autocomplete list #568
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#568
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 @carpii on GitHub (Dec 9, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/776
I have an InputField with an autocomplete function...
I'd like more control over handling key input inside this list. Ive looked at the source but it seems autocomplete list is internal to InputField, and theres no way to access it or add input handlers to it
1) Handling tab and page up/down keys
2) When an autocomplete list item is selected (using arrow keys), I do not want to update the TextInput text. This should only happen when I hit Enter
Maybe I need to write a custom component, or try to handle it from App.SetInputHandler() ?
Any advice much appreciated, thanks
@carpii commented on GitHub (Dec 14, 2022):
Happy to extend the InputField API myself, and submit a pull request
But would appreciate your thoughts on how you see the design working, to maximise likelihood of pull request being accepted. Thanks
@rivo commented on GitHub (Dec 17, 2022):
I think you're right. It currently doesn't work as it's supposed to. Specifically your point (2), I agree it should not update (or especially trigger a changed event) when the user simply browses the autocomplete results. I'm open to changing this despite it being this way right now. (This will fall under the " something that does not work as originally intended" exception regarding backwards compatibility.)
Can you elaborate on your first point, though? I can imagine what PageUp and PageDown should do, but what about Tab?
@carpii commented on GitHub (Dec 17, 2022):
Awesome, thanks.
Sorry, my issue originally explained why I wanted to handle Tab, but I edited it out as it didn't seem relevant.
It's application-specific, in the above list I'd like to type 'Taxe' and then hit Tab.
At this point it would autocomplete the input text to 'Taxes: ' (delimited by colon, and sinces Taxes: would be the only remaining prefix). But the issue is I don't have any way to run a callback when tab is pressed
@rivo commented on GitHub (Dec 17, 2022):
What would be the difference between hitting Tab and Enter?
@carpii commented on GitHub (Dec 17, 2022):
Unless I've misunderstood,
Enterwould accept the currently selected list item, set the TextInput to match that item, and then close the autocomplete listInstead, I want to handle
Tabso I can amend the TextInput from 'taxe' into 'Taxes:', then either select an item from list, or keep typing and add a new 'Taxes: FooBar'.This is very application-specific though, so would not need any Tab-specific code added to InputField (maybe just a way to add a generic hook to the autcomplete list, so any KeyEvent could be handled?)
@carpii commented on GitHub (Dec 22, 2022):
@rivo - I will try to make these changes after Xmas, and submit a pull request.
If you find yourself in the mood to tackle it yourself at any point, I am offering a $100 bounty for it
Cheers
@rivo commented on GitHub (Dec 22, 2022):
I will work on this but I can't do it before Christmas. No need to submit a PR.
I noticed there are some other bugs related to the autocomplete functionality so I need to take a look at them, too.
@carpii commented on GitHub (Dec 22, 2022):
@rivo - I was not sure how it was left, whether you were planning to do it, or whether you were saying you would accept a PR from me. But thanks for looking into it.
I wouldn't expect anyone to work over Xmas though. Maybe if we can be approaching a solution by 1st Feb, the bounty is all yours
Thanks
@rivo commented on GitHub (Dec 22, 2022):
I appreciate it, thanks.
I haven't thought about the Enter vs. Tab thing in detail so I wasn't able to give an informed response yet. But as long as these issues are open, I usually get back to them.
@rivo commented on GitHub (Dec 29, 2022):
Ok, so
b86a50a512introduces a new function calledSetAutocompletedFunc()which gives you more control over how the autocomplete drop-down behaves. If you don't set it, it remains the way it was implemented before (due to backwards compatibility).I believe this should allow you to implement what you needed. Have a look and let me know in case you find any issues.
@carpii commented on GitHub (Dec 30, 2022):
Thanks so much for making these changes. It looks like a nice solution from the diff
I will start integrating it as soon as I can, and let you know how I get on
Cheers
@carpii commented on GitHub (Jan 1, 2023):
Key handling seems to be working well, I'm just unsure how to use the index parameter
Is there a way to retrieve the current entries from the autocomplete dropdown?
Or is the expectation to rerun the same function I use for SetAutocompleteFunc (which would then mean it can no longer be passed as an anonymous fn)
@rivo commented on GitHub (Jan 1, 2023):
That's pretty much it. You might want to cache the results from that function. I didn't want to require a huge function signature repeating information that could be found elsewhere.
You don't have to use the index parameter if you don't need it. You're getting the text anyway.
@carpii commented on GitHub (Jan 1, 2023):
Understood. I just wanted to make sure I wasn't overlooking something obvious :-)
Bit more testing to do, but it's looking good so far. Any preference on how to receive your bounty (Paypal, github etc?)
@rivo commented on GitHub (Jan 1, 2023):
I think since we're here anyway, GitHub is fine. If that doesn't work for some reason, PayPal should do it.
Thank you! 🙏🏼
@carpii commented on GitHub (Jan 1, 2023):
Bounty sent via Github. Thanks for accommodating my feature request, it's a nice enhancement to my project 👍
@rivo commented on GitHub (Jan 4, 2023):
Just to let you know that I haven't received anything yet. My GitHub dashboard also doesn't show any donations/donations made to me.
@carpii commented on GitHub (Jan 4, 2023):
Sorry about that. It looks like my card wasn't billed either
I'll try again now...
@carpii commented on GitHub (Jan 4, 2023):
As far as I can tell, instead of sending it instantly, github is adding it onto my next monthly invoice (on the 18th). Maybe it's because I am a monthly sponsor.
Unfortunately it's not giving me the option to cancel the $100 so I can send via Paypal instead.
I'll see what support has to say
@carpii commented on GitHub (Jan 18, 2023):
Github support didn't respond and I wasn't billed on my invoice either
I think one-off github sponsorships are just buggy if you're already a monthly sponsor
I've now sent via Paypal instead, sorry it took a while
@rivo commented on GitHub (Jan 19, 2023):
No problem at all! I appreciate your support, thank you!