[Action, Shortcut] How to force IDE to use action shortcut?

Hi all,

I am trying to find how I can force IDE to execute my action when action shortcut is invoked. 
Usually this is not an issue, unless actions shortcut overlaps with any existing IDE shortcut.

In my case I would like to execute action on `ctrl enter`. However in IDE for this shortcut is bind "split line" action.

Let's take this action definition as an example.
  <action id="MyPlugin.EditorAction" class="my.plugin.EditorAction" text="Make action in editor!">
    <keyboard-shortcut first-keystroke="ctrl enter" keymap="$default"/>

When I explore how this action is shown in IDE - it correctly says that shortcut is `ctrl enter`.
But when I actually try to execute this shortcut - it splits lines, instead of executing my action.

Comment actions Permalink

The issue is that there are multiple actions with the same shortcut available in given context. In this case we don't know which one to execute, and pick the first one.

You can use com.intellij.openapi.actionSystem.ActionPromoter to prioritise your action over the others.

But, please, think twice before stealing a such common shortcut.

Comment actions Permalink

Thanks, @Alexey - I will try your solution.

I am creating a plugin which will allow the user to execute queries in the database (similar to what Database support plugin is doing).
In this case, users are expecting that queries can be invoked via "ctrl-enter" shortcut, while the cursor is placed in the file.

So, in theory, I want this shortcut to be active only in editor context.

Comment actions Permalink

Thanks @Aleksey!

ActionPromoter works perfectly and was exactly what I looking for.


Please sign in to leave a comment.