My plugin is adding completions to HTML files, and one thing that’s kind of odd is that during autocompletion, the first entry in the completions list is not automatically selected, and pressing Tab or Enter inserts a paired HTML element based on the typed text:
As you can see above, I reproduce that behavior once, then I repeat the process and explicitly use the Down key to choose the first completion so that it’s inserted on Tab or Enter.
Is there any way I can override this behavior for these specific completions?
What IJ Platform version do you use? Does updating to the latest version help?
Do you observe the same behaviour (no item selected) without your plugin?
My plugin is adding completions to HTML files
Could you explain how exactly you add items? Do you just register your CompletionProvider or you have some additional code that spawns completion lookup?
This is all on the latest, though I’ve seen this behavior for quite a long time.
Well, that’s difficult to say because without my plugin, there are no additional completions being added to try to reproduce the behavior.
Yeah, it’s just a standard completion.contributor EP implementation that uses extend to register a CompletionProvider that in turn creates LookupElements and adds them to the provided CompletionResultSet. This is one of ~20 completion providers added by my plugin, and the only ones that behave in this manner are the ones that add completions to HTML files. There seems to be something specific about how completions are handled in that language/file type – specifically autocompletions – that results in this “unfocused” completion selector.
Let me know if there’s any other info I can provide.
@illuminatedcloud I think you’re seeing Emmet/Zen coding tag insertion. You can turn the feature of in the settings to see if that’s the culprit.
I don’t know how to override that, though
Good thought, and that’s definitely coming into play here. If I disable Emmet in HTML, Tab doesn’t insert the element pair…but it also doesn’t insert any of the offered completions because none is selected by default:
My guess is that if there was an initial selection, it would behave as desired/expected without having to disable/override Emmet.
But that does explain the current behavior. Good eye!
It’s going to require my plugin to be installed, so let me see if I can come up with the easiest/most straightforward repoduction steps for you. More to come shortly…
It seems that com.intellij.codeInsight.completion.HtmlCompletionContributor#shouldTryDeselectingFirstPopupItem gets into your way. IIUC there is no way to customize its behavior from a plugin.
Based on that lead, I was able to implement completion.htmlInTextCompletionPopupExtension to return true from isDeselectingFirstItemDisabled when the provided element is in a context where my plugin specifically contributes completions. That provides the desired/expected behavior, and given that I’m very carefully only returning true in the exact scenario where my plugin contributes completions, it shouldn’t change the standard HTML behavior.
That EP is annotated as @ApiStatus.Internal, but I’m assuming you’re okay with me implementing it until/unless the YT issue linked above is addressed, no?