TypedHandlerDelegate not catching all characters
I have a very bare bones TypedHandlerDelegate implementation. Basically the code logs out the typed character and returns `Result.CONTINUE;`. In my plugin.xml it's declared with `<typedHandler implementation="TypingHandlerDelegate" order="first"/>`. When I type quickly, for example "lorem ipsum", it logs out something like "lorm isu". Some of the characters, it seems, are not sent to the callback at all. It doesn't matter if I use the beforeCharTyped or charTyped callback. Is this some kind of performance optimisation? For my plugin I really need all the characters (I'm counting them). How can I have all characters sent? You can see the code at https://gitlab.com/code-stats/code-stats-intellij/-/blob/wip/2020-refactor/src/TypingHandlerDelegate.java -- as you can see I've removed most of the code so it wouldn't interfere. I'm still losing characters.
Please sign in to leave a comment.
beforeCharTyped is supposed to be called for each caret event:
https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java#L183
You may try to debug this class.
I got investigated a bit further. Whenever a suggestion is open, the typed characters are not sent to the delegate. So for example when I type "public", only "p" is sent to the delegate. For the rest of the characters, the suggestion popup is open and then characters are not sent. Why does this happen and how can I get those characters too?
You should try with editorTypedHandler extension point:
In execute method you can get the access to charTyped character. You should also remember to invoke the original handler, like:
Thanks, where do I put that extension point? I put it in the <extensions> part in plugin.xml and implemented the class like you showed and now no typing works anymore. I.e. when I type, nothing happens, no text is input. Trying to debug, the constructor for the typed action handler and the execute function are never called (breakpoints never hit).
And before you ask, I did remember to call the original handler. :) Like you showed.
Indeed, it should be specified in plugin.xml, like:
https://github.com/JetBrains/intellij-community/blob/04c159668c216f0953ece8ec725f1c6958c922b0/java/java-impl/src/META-INF/JavaPlugin.xml#L1145
Well like I said, when used like that, no characters are input and the handler is never called at all.
Can you please prepare a minimal reproducible example so I can run it locally?
You can try this branch: https://gitlab.com/code-stats/code-stats-intellij/-/tree/wip/2020-refactor (the wip/2020-refactor branch).
It's mostly commented out in the TypedActionHandler so it should be quite minimal.
The problem was that you've named your class exactly as the constructor parameter type:
If reviewing the logs, you'll notice PicoContainer exceptions regarding the unsatisfiable dependencies:
In addition, I've updated your configuration to use Gradle and set proper dependencies.
Please review the pull request.
Ah of course. Sorry about that, I only have a little time for this every evening and screwed that up. Thanks for your help, I will test your PR this evening. :)
Thanks for the help, I was able to fix the code. I could not get your Gradle build to work, but I took the code changes.
Now I have a follow-up issue. I want to get the language of the document that was typed in (or even better, the language that was actually typed, like if you type SQL into a Java file for example).
I used to use this code snippet, but is this really the most straightforward way? https://gitlab.com/code-stats/code-stats-intellij/-/blob/master/src/TypingHandler.java#L20-33
Try with:
It takes the current caret out of the provided Editor, so you'll be able to get the exact language basing on the cursor position.