-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support suggestions and autocompletion in textinput #407
Conversation
@maaslalani In my implementation here: #140 there was an |
This is awesome @toadle! Thank you so much! |
@maaslalani You think we can get this merged? There was one thing that I was still thinking about: If there are several suggestions populated
and you currently have "Hello" typed in, you can switch through all three. Ending up in the last situation where there is nothing to complete when having "Foo bar" selected, because "Hello" can not be completed to "Foo bar". Should the autocomplete work in a way where the input also looks for the next possible suggestion if the current one can not be used to complete? Effectively switching the current selected suggestion. The otherwise to do it would be to always switch the possible suggestions externally. I kind of have the feeling that it should cause it'll be more useful that way. But I also would like to get this merged ;-) |
Anyway, forget my last comment. I just fixed it here: 2d16f32 Should be good to go. I hope we can merge this, so that it doesn't get stale again :-) |
@toadle so what you're saying is that you're building a bubble tea integration called |
@meowgorithm Unsure if pun or not :-)?! |
@toadle Totally joking around. This looks awesome! |
@maaslalani What do you say? |
Going to try and get this merged today! Thanks so much for all your work @toadle. |
@maaslalani I saw that you removed the Msg to set suggestions in the recent commit. Please remember that suggestions most likely will get stemmet asynchronously by the result of another cmd. We discussed that over on the other PR. Would you still set them via a func-call then? |
Yep, I will add the asynchronous setting back since many people may get their autocompletion data from an API or external source. But we should definitely also allow setting the suggestions statically since a lot of people may already have the values beforehand when creating the textinput bubble. |
Hey @toadle looks like this PR will need some adjustments to get double width runes working: I can handle that soon! |
@maaslalani OK, that double-width rune thing is weird. I tried to fix that myself just now but always end up with the same problem. I'll also have a look if I can fix that. I pushed a little other change where I expose a function that can help customize to complete behaviour (e.g. if you want to complete just up to the next "space" or "-"). I think it'd be good to have that - I can think of several use-cases. |
also: accepting suggestions does not overwrite the already given input, rather appends
@maaslalani Finally understood how |
Amazing @toadle! I will take a look and merge this soon 🎉 |
@toadle after doing a bit of testing it's definitely possible to use the SetSuggestions stuff with custom commands on the developer end. So I say we merge this as is. For example, a user can do the following: type setSuggestionsMsg []string
func loadSuggestions() tea.Msg {
time.Sleep(5 * time.Second) // Fetch from a data source.
return setSuggestionsMsg(pokemon[0])
}
// ... Update method.
case setSuggestionsMsg:
m.textInput.SetSuggestions(msg) Since the user can implement a basic |
Also tested with double width runes and everything is working great! |
@maaslalani If that works too i think it is also fine to have it work like this. In my tests it somehow did not work, but my implementation already differs quite substantially from the one here. So the error might be in my side. |
* migrate all autocomplete-work from old branch * added support for multiple suggestions * fix linter issues * refactored to only offer matching suggestions for completion * fix: SetSuggestions + Suggestions * make: configuration behaviour configurable * fix for double-width runes * refactored all suggestions to be rune-arrays also: accepting suggestions does not overwrite the already given input, rather appends * fix: make suggestions and OnAcceptSuggestions unexported * refactor: refreshingMatchingSuggestions -> updateSuggestions --------- Co-authored-by: Maas Lalani <maas@lalani.dev>
Continuation of discussion from here: #140