All I want for Christmas...

Is to be able to:

1. press ctrl-space and set a mark
2. move my cursor around screen and have text highlighted

That's all!

IDEAmacs is a great start, but OpenAPI doesn't seem to support the ability to highlight text like when you hold 'shift'.

Naturally, I first tried SelectionModel.setSelection, but, um that doesn't do any highlighting. And, I'm not even sure it does anything.

Next, I tried MarkupModel.addRangeHighlighter(), but with no documentation on any of those methods, I don't know what layer it should be on or what several other options are. I got it to highlight, kindof, but it only boxes the region on the line that the cursor is on, but if I move, it will change that line to the color I set in TextAttributes.

I could almost live with that, but it seems to save the file every freaking second and so if I delete a region, I can't undo it!

Is there any documentation that someone can point me to to show me how to highlight text EXACTLY AS IF I WAS HOLDING DOWN THE SHIFT KEY.

Thanks,
Michael

13 comments

Hello Michael,

MN> Naturally, I first tried SelectionModel.setSelection, but, um that
MN> doesn't do any highlighting. And, I'm not even sure it does
MN> anything.
MN>
MN> Next, I tried MarkupModel.addRangeHighlighter(), but with no
MN> documentation on any of those methods, I don't know what layer it
MN> should be on or what several other options are. I got it to
MN> highlight, kindof, but it only boxes the region on the line that the
MN> cursor is on, but if I move, it will change that line to the color I
MN> set in TextAttributes.
MN>
MN> I could almost live with that, but it seems to save the file every
MN> freaking second and so if I delete a region, I can't undo it!
MN>
MN> Is there any documentation that someone can point me to to show me
MN> how to highlight text EXACTLY AS IF I WAS HOLDING DOWN THE SHIFT
MN> KEY.

First of all, please upgrade to IntelliJ IDEA 5.0.2. It contains a significant
amount of new documentation, and in particular, all editor-related interfaces
(including SelectionModel and MarkupModel) are fully documented.

The method you need to perform the selection is SelectionModel.setSelection().
Could you please show a code sample showing when and how you invoke it? It
performs the highlighting and everything else as required.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

I have 5.0.2 but was using the online documentation for 5.0 (http://www.jetbrains.com/idea/openapi/5.0), sorry about that.

Where is the correct documentation? I don't see any in the installation directory.

0

Hello Michael,

MN> I have 5.0.2 but was using the online documentation for 5.0
MN> (http://www.jetbrains.com/idea/openapi/5.0), sorry about that.

That's our fault - the online documentation indeed has not been updated for
5.0.2. We'll fix this right away.

MN> Where is the correct documentation? I don't see any in the
MN> installation directory.

The documentation is included in the Plugin Development Package, which you
can download from:
http://www.jetbrains.com/idea/plugins/plugin_developers.html

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

DJ> The method you need to perform the selection is
DJ> SelectionModel.setSelection(). Could you please
DJ> show a code sample showing when and how you invoke
DJ> it? It performs the highlighting and everything
DJ> else as required.

IDEAmacs has a caret listener. It also has something that handles recording when the user sets a 'mark'.

caretPosition ? caretPosition : mark; int stop = mark < caretPosition ? caretPosition : mark; org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(getClass()); log.info("setting selection to: " + start + " - " + stop); editor.getSelectionModel().setSelection(start, stop); } }]]>

I added a new action to unset the mark. When this action is triggered, it simply calls:



I am by no means an IDEA expert, so please let me know what I'm doing wrong.

Thanks,
Michael

0

I put a editor.getSelectionModel().hasSelection() check in the caret listener, and it seems that every time it comes into the method, the selection has been removed.

So that when it comes in, hasSelection() == false, but after I set the selection, hasSelection == true.

Something is removing my selection after the caretPositionChanged() method is called...

0

I put a SelectionListener on the SelectionModel and sure enough something is erasing my selection every time the caret moves.

So, caret moves, I check mark, set selection. Then, the normal caret listener fires and he sees that the SHIFT key is not down and clears any selections.

So, there must be a modifier in the caret model code somewhere that checks for a 'highlight modifier' to be pressed and then it doesn't remove the selection.

Why don't you guys abstract out that 'modifier' check into a binding? That would solve all my problems.

Thanks,
Michael

0

caretPosition ? caretPosition : mark; int stop = mark < caretPosition ? caretPosition : mark; org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(getClass()); log.info("setting selection to: " + start + " - " + stop); log.info("has selection? " + editor.getSelectionModel().hasSelection()); editor.getSelectionModel().setSelection(start, stop); log.info("has selection? " + editor.getSelectionModel().hasSelection()); } } public void selectionChanged(SelectionEvent e) { // HACK: wait for the normal code to clear the selection then, put it back if (!editor.getSelectionModel().hasSelection()) { int mark = editorComponent.getPositionManager().getMark(); int caretPosition = editor.getCaretModel().getOffset(); if (mark != -1 && mark != caretPosition) { int start = mark > caretPosition ? caretPosition : mark; int stop = mark < caretPosition ? caretPosition : mark; org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(getClass()); log.info("setting selection to: " + start + " - " + stop); editor.getSelectionModel().setSelection(start, stop); } } }]]>

Added the above hack to get it to work. I have to still set the selection in the original actionPeformed because the code that checks for SHIFT and then calls removeSelection must check hasSelection first.

Michael

0

Now, the problem is that when ever I kill something using the KillRegionAction, I can't undo the action.

A little popup says: Cannot undo. Some files where changed.

What causes this? I did not 'save' the file.

0

Got around this problem because it was calling the deprecated version of CommandProcessor.executeCommand. I switched to the new style and passed UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION and now I can undo my kills.

I think that just about covers it...

0

I miss the same functionality that you did. Was your code something you added to ideamacs, or something standalone? Would you share you solution with me/us? Thanks!

-Cris

0

Did you file Jira request?
I think this is core editor funcationality that JetBrains should consider doing themsevles.

It's not just Emacs. Firefox works like that to. I can click on a page and then hold SHIFT or CTRL+SHIFT and the arrow keys to extend the selection.

I use Select Word CTRLW and CTRLSHIFT+W all the time which works great for hilighting java expressions, but sometimes you need to adjust the selection and also for non-java files it is more important.

Unfortunately, the direction Demetra is headed it looks they are spending most of the developer's time added non-core features like continous build integration, project servers, inspection servers, collaboration, enhancements to ui designer..

0

Hello Alex,

A> Unfortunately, the direction Demetra is headed it looks they are
A> spending most of the developer's time added non-core features like
A> continous build integration, project servers, inspection servers,
A> collaboration, enhancements to ui designer..

One important thing that needs to be clarified: small features like this
one (a new way to extend selection in the editor) are not "roadmap-level"
features. The roadmap lists major new improvements - things because of which
people will want to upgrade to the new version. Even if we could list every
minor enhancement like this one in advance, the roadmap would be dozens of
pages long - and usually we can't list the enhancements in advance because
many of them are implemented directly based on user feedback and suggestions.

We do have a core team working exclusively on core features, so there will
be many improvements in the core functionality.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Yes. I posted my code as a patch to the IDEAmacs sourceforge site. You can download it there.

Michael



Attachment(s):
ideamacs.zip
0

Please sign in to leave a comment.