Wednesday May 21, 2014

Expand Selection to Word

A nice idea by Dmitri Goosens on Twitter today, based on the rectangular block selection that has been a standard part of NetBeans IDE for a few releases already.

The idea with this functionality, known as "block selection" or "rectangular selection", is that you can switch on "block mode" and then select across lines and change text all at the same time:

Here you can see, I have changed "multiple" to "many" simply by selecting a block of "multiple" and then typing, just once, "many":

However, what if you want to change only some of the instances of "multiple" and what if they're not neatly lined up like above? That's the point Dmitri Goosen made on Twitter today.

So I started creating a plugin that lets the user select (by double-clicking) the words that should be changed all in one go. Right now, only the selection works, which was quite a bit of work to get right.

Below you can see that only some of the "multiple" words are selected, i.e., I created a plugin that turns any selected word/s into a specially highlighted area, not with the standard yellowy background, but by making the borders of the selected word/s blue:

When you press Escape, all the blue borders disappear, i.e., nothing is then selected anymore.

Here's the sources:

Would be great if someone would clone them and then add code for changing the selected word/s to whatever the user types. A basic implementation is as follows, where the workflow is (1) select multiple words and then (2) press F12 to popup a small dialog where you can enter the replacement text. Then (3) press OK to perform the replacement.

Inline replacement will be better, same as replacement after block selection.

This could be incredibly powerful feature in NetBeans, i.e., imagine being able to select arbitrary words in a file and change all of them at the same time.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« May 2014 »