-
Notifications
You must be signed in to change notification settings - Fork 41
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
New UI component like quick panel but where the plugin controls results when user is typing #4796
Comments
Instead of a whole new API for this (which doesn't seem any different from a Edit 1: I guess it would be something similar to |
You're right that the API isn't much different, but as the functionality differs quite a lot, I felt a discrete API would make more sense - also to prevent the chance of regressions for the current use of list input handers, and to keep the API simpler rather than needing documentation like "if x then this behavior, otherwise that behavior" etc. |
The critical issue is that What I described in #3338 avoids a promise-based API by letting the plugin handle that via update calls. |
Maybe I'm missing something, but the current ST3 compatible hacky implementation of the XPath plugin works fine without promises, so this would still be a major improvement even without them. But sure, we could change the proposed API slightly to avoid the need for promises here too. I can see how that or promises may make it more useful. But then, another question arises. If the user continues to type and it takes a while to get the new list of items to show, what should be displayed meanwhile? For XPath, it could be useful to show a loading icon or something instead of the previously valid list of items, or to visually dim the list to show it isn't current based on the provided input. |
We can just look at how VSCode does it no? Peek.2021-08-29.13-28.mp4The Goto Symbol In Project (aka Workspace Symbols) in VSCode refreshes the list on every keystroke asynchronously. Note how there's a small delay between me typing the identifier and the result list refreshing. There is no UI indication that this is async. |
This is actually a duplicate of #908, but I'd prefer this issue since it goes into more detail and outlines some use cases. |
Cancel/Discard any but the latest promise. As for XPath in particular, would it be reasonable to build the xpath query entirely in the command palette but with multiple consecutive input handlers for each part of the query? Can we utilize the auto complete popup there as well? I imagine that would be quite a bit of effort to get right but supposedly it could be achieved with existing tools. |
Problem description
Currently, a quick panel and a
ListInputHandler
can only show predefined entries. When the user types, ST filters those entries using fuzzy matching.For some use cases, it would be useful to have a similar UI component to those, but when the text in the input widget at the top changes, a callback should be invoked so that the plugin would be able to dynamically update/remove/add the results/items in the list.
Specifically, the use-case I have in mind is when querying an XML document using the XPath query language. The user could type in the XPath expression, and the plugin would show items that match, which the user can preview/navigate to with the up/down arrow keys as normal or click on one/press Enter to select it. ST should do no filtering/fuzzy matching of it's own here.
Preferred solution
A new API added to allow a plugin to show a "dynamic input panel".
a new
sublime_plugin.DynamicChoiceInputHandler
class:name()
str
foo_bar
for an input handler namedFooBarInputHandler
get_list_items(text)
[ListInputItem]
or([ListInputItem], int)
placeholder()
str
initial_text()
str
initial_selection()
preview(value)
str
orsublime.Html
validate(value)
False
to disallow the current value.cancel()
None
confirm(value)
None
next_input(args)
CommandInputHandler
orNone
None
to indicate no more input is required, orsublime_plugin.BackInputHandler()
to indicate that the input handler should be popped off the stack instead.description(value, text)
str
want_event()
bool
validate()
andconfirm()
methods should receive a second parameter, an eventDict
Alternatives
Continue to use ugly hacks like showing an input panel (which spans across the whole editor at the bottom instead of just in the active group), showing a quick panel when the user types/pastes something in said input panel, then switching input focus back to the input panel. And when the user types again, close the quick panel, reopen it with new items, refocus the input panel... And deal with the up/down arrow keys sometimes changing the quick panel selection, sometimes moving the caret in the input panel...? 😅
![image](https://user-images.githubusercontent.com/11882719/131227890-cd59f563-eb27-41b8-bef1-af5a76442b03.png)
Additional Information (optional)
In case this seems familiar, I am splitting it off from the feature request at #3338 (comment), because it seems for the LSP use case, ST should still do filtering, but for this use case, ST should do no filtering, just allow the plugin to update the list of entries displayed while the user is typing.
You can take a look at the gifs in the XPath plugin's readme for an idea of how it looked in ST3 with just one group in the layout.
It would be great to hear from others to see if this API could be put to good use in other plugins too :)
The text was updated successfully, but these errors were encountered: