Language Console autocomplete popup problem Follow
Hi all,
In my language console implementation I'm using a custom action assigned to the Enter key, similar to the way the Clojure plugin works. However this stops the Enter key working in the autocomplete popup - can I detect if the user is currently in the popup and do something different?
Cheers,
Colin
Please sign in to leave a comment.
How do you register your action? You should probably use editorActionHandler extension.
I'm using some code that I got from the Clojure plugin:
AnAction enterAction = new REPLExecuteAction(project, repl);
EditorEx consoleEditor = repl.getConsoleView().getConsole().getConsoleEditor();
enterAction.registerCustomShortcutSet(enterAction.getShortcutSet(), consoleEditor.getComponent());
enterAction.registerCustomShortcutSet(enterAction.getShortcutSet(), panel);
where REPLExecuteAction extends DumbAwareAction, and has this in the constructor:
EmptyAction.setupAction(this, SchemeConsoleRunner.EXECUTE_ACTION_ID, null);
panel in the above code is the JPanel which is the ToolWindow content. Does that look right? I'm not sure how I would register this as an extension point, since I only want it in the Language Console.
No, that doesn't look right. Well, it works, but it's doomed to ignore lookups and some other things. Using the extension would give you a possibility to give them a chance. And to make it work only in your console, the very first line of your extension should check that, and if it's not given your console editor, then invoke the next handler. You should invent a way of understanding that some editor is yours, the simplest and the dirtiest one is to use its user data.
That works great, thank you! For the record, here's what I did:
EditorActionManager manager = EditorActionManager.getInstance();
EditorActionHandler replEnterAction = new REPLEnterAction(manager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER));
manager.setActionHandler(IdeActions.ACTION_EDITOR_ENTER, replEnterAction);
assert (replEnterAction == manager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER));
in an ApplicationComponent. This is straight from the Groovy source code.
ApplicationComponents slow down the startup. It would be better to have something like that in your plugin.xml:
<editorActionHandler action="EditorEnter" implementationClass="com.intellij.codeInsight.editorActions.EnterHandler" order="..."/>
Ok, thanks. If I do that, will I get the previous handler injected into my constructor?
Yes
Hi Peter,
I've installed my editor action handler as you suggested, and it works fine. However I've noticed another problem that this provokes - the enter key now doesn't work correctly in dialog boxes or debugger fields. For example, if I'm renaming a class, when I press enter it will insert a carriage return in the name instead of selecting Ok. The same thing happens in debugger watch fields (and I'm sure a lot of other places). It doesn't seem to matter which order I put the handler in. I've attached the code I'm using below - is there anything obvious wrong with it?
Cheers,
Colin
<editorActionHandler action="EditorEnter"
implementationClass="schemely.repl.toolwindow.actions.REPLEnterAction"
order="FIRST"/>
public void executeWriteAction(Editor editor, DataContext dataContext)
{
REPL repl = editor.getUserData(NewSchemeConsoleAction.REPL_KEY);
if (repl == null)
{
originalHandler.execute(editor, dataContext);
}
else
{
// Do my thing here
}
}
It seems that you also have to override isEnabled() there and (at least) delegate it to the original handler.
Excellent, that seems to work - thanks!