【问题标题】:How can I add another EditorActionHandler to a single IdeAction without losing functionality?如何在不丢失功能的情况下将另一个 EditorActionHandler 添加到单个 IdeAction?
【发布时间】:2019-09-19 05:00:52
【问题描述】:

我有一个插件,我想在用户触发 BACKSPACEDELETE 键时添加附加功能,而不会丢失初始功能(在这种情况下,字符删除)。

我正在尝试为指定的ideActions.<ACTION_EDITOR_VALUE> 覆盖EditorActionHandler

public class MyPlugin implements BaseComponent {

@Override
public void initializeComponent() {

    final EditorActionManager editorActionManager = EditorActionManager.getInstance();
    EditorActionHandler originalBackspaceHandler = editorActionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);

    EditorActionHandler eaHandler = new EditorActionHandler() {
        @Override
        protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
            super.doExecute(editor, caret, dataContext);

            originalBackspaceHandler.execute(editor,caret,dataContext);

            PsiElement e = dataContext.getData(CommonDataKeys.PSI_ELEMENT);
            if(e != null) {
                System.out.println("psi Element" + e.toString());
            }
        }

    };        
  editorActionManager.setActionHandler(IdeActions.ACTION_EDITOR_DELETE,  eaHandler);   

} //initalizeComponent()   
} //MyPlugin

这是在保持当前功能的同时覆盖editorAction 处理程序的首选方式吗?我想定位其他IdeActions.<VALUES> 并重复使用相同的EditorActionHandler

【问题讨论】:

    标签: java intellij-idea intellij-plugin


    【解决方案1】:

    没有通用的方法来覆盖动作处理程序。您的方法是其中一种可能性。

    例如Heresmart step into 处理“右箭头”、“左箭头”等的代码。使用类似的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-19
      • 2021-09-29
      • 1970-01-01
      相关资源
      最近更新 更多