How to delegate backspace and Enter button in TypedActionHandler?
I want to run execute() after backspace or enter key pressed. Currently this works only when a character key is pressed.
public class MyTypedHandler implements TypedActionHandler {
private TypedActionHandler myOriginalHandler;
public MyTypedHandler(TypedActionHandler originalHandler){
myOriginalHandler = originalHandler;
}
@Override
public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext){
myOriginalHandler.execute(editor, c, dataContext);
Document document = editor.getDocument();
Project project = editor.getProject();
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow("SCA_Tool");
Runnable runnable = new Runnable() {
@Override
public void run() {
}
};
WriteCommandAction.runWriteCommandAction(project, runnable);
}
}
请先登录再写评论。
For Enter and Backspace there are separate extension points - see EnterHandlerDelegate and BackspaceHandlerDelegate.
I tried adding two extension points but it didn't worked. Same as this case when I tried to delegate to original typing behaviour https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000597339-Why-I-can-t-see-what-I-type- . But I resolved typing behaviour using myOriginalHandler.
What is the specific problem you have with those new extension points?
I don't get any errors. The plugin runs and works but execute() doesn't run when enter key or backspace is pressed. Works fine for any character.
I added extension point for enter key delegation as follows.
There's no 'execute' method in EnterHandlerDelegate. It has its own methods you'll need to overwrite. Looks like you've added an empty implementation.
For that do I have to make a new file called EnterHandlerDelegate.java? I only need to make TypedActionHandler run its execute() for enter and backspace keys as well. Currently it works for any character key.
Yes, you'll need your own implementation of EnterHandlerDelegate. Typed handlers are not invoked for Enter and Backspace.
It worked. Thanks. But when I select one or more characters and press backspace it doesn't work.
If you want to handle such situations as well, you'll need a different approach - register EditorActionHandler for backspace action (actionId=EditorBackSpace). You can check how com.intellij.codeInsight.editorActions.BackspaceHandler is registered in IDEA CE codebase for an example. It's similar to TypedActionHandler, original handler is passed to it, and it should delegate requests to it, if default backspace behaviour should be preserved.
I'll try. Thanks.
@... The solution Dmitry proposed worked for me. Here's my code:
plugin.xml
BackspaceActionHandler.kt