CaretListener.caretPositionChanged works only with mouse events
Hi,
I'm writting a caret listener and I noticed that caretPositionChanged is called only when the caret's position is changed via the mouse. If I move the caret with the left/right/up/down arrow, the method is not called.
Any idea?
Thanks,
-Vincent.
请先登录再写评论。
Really strange thing. A lot of IDEA's functionality would be broken if that
is true. Could you please post a code snippet?
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"
"Vincent." <no_mail@jetbrains.com> wrote in message
news:11553498.1064299481513.JavaMail.itn@is.intellij.net...
>
called only when the caret's position is changed via the mouse. If I move
the caret with the left/right/up/down arrow, the method is not called.
>
>
Hi Maxim,
I'm trying to implement an Emacs-like SetMark feature. After I've set a mark in the editor, I want the selection to change as I move the caret (i.e. I want teh text between the mark and the caret to be selected)
With the following code, teh selection changes as I move the mouse but not when I move teh caret with the arrows.
I'm new to the plugin API (and to IDEA for that matter), so I guess I'm missing something obvious.
Thanks,
-Vincent.
public class EditorListener implements CaretListener
{
....
public void caretPositionChanged( CaretEvent event ) {
editorComponent.getKillRing().resetPos();
// Set the selection if the mark is set
if (editorComponent.getPositionManager().isMarkSet()){
Application application;
CaretModel caretModel;
application = ApplicationManager.getApplication();
int markPos = editorComponent.getPositionManager().getMark();
caretModel = editor.getCaretModel();
int pos = caretModel.getOffset();
editor.getSelectionModel().setSelection(markPos,pos);
}
}
}
Maybe a silly question, but: have you verified, through println,
that the caretPositionChanged method is not being entered?
Vincent wrote:
--
Erb
==============================================================
"Most of you are familiar with the virtues of a programmer.
There are three, of course: laziness, impatience, and hubris."
- Larry Wall
==============================================================
I added some traces and moving the caret with the arrows does indeed trigger the handler (caretPositionChanged).
Now, what I don't understand is why the following line:
editor.getSelectionModel().setSelection(markPos,pos);
does not cause the code between teh mark and the caret to be highlighted. Do I need to repaint the editor or something?
Thanks,
-Vincent.
And the mark and pos are definitely different in this case, right?
(Sorry, again, I have to ask)
Vincent wrote:
--
Erb
==============================================================
"Most of you are familiar with the virtues of a programmer.
There are three, of course: laziness, impatience, and hubris."
- Larry Wall
==============================================================
Yes, they are different.
-Vincent.