JTextPane and VK_HOME
Hi,
I have a JTextPane in my plugin, and I want it to have custom VK_HOME event handler, which would move the caret to the beginning of the last line. However, it looks like IDEA takes over and first moves the caret to the beginning of the whole text, so the caret jumps twice. Here's relevant stack trace, taken from the caret listener:
What is the civilized way to overcome it? I don't want to hack JTextArea.setCaretPosition
Thanks
请先登录再写评论。
Hello Konstantin,
You need to implement the Home key handling as an AnAction and use registerCustomShortcutSet()
to associate the Home key with it. Then your handler will be called instead
of IDEA's own Home key handling.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello Dmitry,
Thanks, it works, but raises another question: specifying keyboard-shortcut for my actions in plugin.xml makes them visible and editable in IDE preferences, but also makes them global. For instance, I want to define a HistoryUpAction mapped to the 'UP' key by default, which will only work inside of my tool window. Setting <keyboard-shortcut keymap="$default" first-keystroke="UP"/> overrides 'UP' key for the whole IDE, which is very inconvenient of course because the 'UP' key stops working in lots of dialogs. Is there a way to tell IDEA not to do it?
I'd still like to see my default shortcuts in the keyboard layout editor though, but I'll also have to call registerCustomShortcutSet again if the user changes the layout I guess.
Hello Konstantin,
Do not register your action in plugin.xml. Simply create an instance of your
AnAction-derived class programmatically, and use registerCustomShortcutSet()
to associate it with a component.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello Dmitry,
OK, but how to make their shortcuts configurable then? They won't show up in configure->keymap->plugins->(my plugin)..
Hello Konstantin,
Your action should call presentation.setEnabled(false) in its update() method
if it's not in the appropriate context. Then it will not interfere with the
standard IDEA up action.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello Dmitry,
Many thanks, now it works as I want it to :)