What happens when multiple plugins register a custom shortcut to the same component?

What happens when two actions register the same custom shortcut to a component (say the editor) via AnAction.registerCustomShortcutSet()? IdeaVIM has registered a shortcut via this method that I want to steal. Unfortunately, IdeKeyEventDispatcher only notifies the first registered action whose presentation is enabled. How do I get the dispatcher to call my action?

0
2 comments
Avatar
Permanently deleted user

In case anyone is interested, I figured out how to hijack the keystrokes from another plugin that has registered a custom shortcut to a component via AnAction.registerCustomShortcutSet(). You need to use a special key called ACTIONS_KEY together with JComponent.putClientProperty() - there is a special utility class in the IntelliJ Platform API that will also do this for you. Remember to save the original list of AnAction that ws bound to a component, so you can restore it when you're finished.

// First get the original list of actions for a JComponent
SmartList<AnAction> original = com.intellij.util.ui.UIUtil.getClientProperty(editor.component, ACTIONS_KEY)
//... now replace the list with ourAction
com.intellij.util.ui.UIUtil.putClientProperty(editor.component, ACTIONS_KEY, SmartList<AnAction>(ourAction))
ourAction.registerCustomShortcutSet(ourCustomShortcutSet, editor.component)
//... when we're all done, reset the original action list
com.intellij.util.ui.UIUtil.putClientProperty(editor.component, ACTIONS_KEY, original)
0

Maybe com.intellij.openapi.actionSystem.ActionPromoter can help.

0

Please sign in to leave a comment.