Editor handling of mouse double-click

I was going to file a bug on the way that the Intellij editor handles double-click, but I thought I'd first look at the documentation and see if my assumptions about what the editor should do and what the editor is documented to do line up. But I wasn't able to find information on what the editor does on double (or triple) click in the Intellij documentation.

The behavior I'm wondering about is double-click on delimiters such as {} or () (or even "" and ''). In eclipse the editor selects the text (expression/statements/data/etc) inside the delimiter, which I think is pretty handy. In Intellij double-clicking on { or } sometimes selects the contents and sometimes selects something else, or nothing at all.

Anyone know what the editor is supposed to do, and if so if it's doing it correctly?

As a side node, I noticed that the editor preferences let you remap mouse events, but it doesn't look like there's a way to search by them.  That is, with keystrokes you can use a filter to search for bound keys, but I didn't see a way to create a filter to search for bound mouse events.

3 comments

pshapiro wrote:

I was going to file a bug on the way that the Intellij editor handles double-click, but I thought I'd first look at the documentation and see if my assumptions about what the editor should do and what the editor is documented to do line up. But I wasn't able to find information on what the editor does on double (or triple) click in the Intellij documentation.

The behavior I'm wondering about is double-click on delimiters such as {} or () (or even "" and ''). In eclipse the editor selects the text (expression/statements/data/etc) inside the delimiter, which I think is pretty handy. In Intellij double-clicking on { or } sometimes selects the contents and sometimes selects something else, or nothing at all.

Anyone know what the editor is supposed to do, and if so if it's doing it correctly?




You'll find overall that IDEA is more keyboard centric than mouse centric. Everything you describe can be done via keyboard shortcuts. In particular the CTRL+W shortcut. Most of the things you describe can also be accomplished via mouse clicks. For more information on CTRL+W (which is very powerful and useful), see
Help > Help Topics > Getting Started  With IntelliJ IDEA > Familiarize Yourself with IntelliJ IDEA Editor  > Basic Editing Procedures > Selecting Text in the Editor


Here are some general points:

  • Double clicking an identifier (or a word in a string literal) will select it
  • Placing your cursor on a word or identifier, and typing CTRL+W will progressively select the work, the sentence, the parameter, the method call, etc. Pressing CTRL+SHIFT+W will progressively deselect items. Overall, this is far more powerful than what can be done via mouse clicking.
  • Double clicking ON a brace, '{' or '}', will select the entire block of that brace.  Typically, double clicking just outside the brace will also select the entire block. The behavior of double clicking just inside a brace will depend on the structure. For example, in the statement {String s;}, clicking just inside the opening brace will select the 'String' identifier. This is because the editor gives preference to interpreting clicking in front of something over clicking after something. So it interprets that double click as double clicking on "String" rather than the brace. However, if I have { String s; } and double click just after the opening brace (i.e. either between the brace and the space, or on the space (or line return) after it), IDEA will select the entire block.
  • Placing your cursor just to the left or right of a brace, '{' or '}', and typing CTRL+W will select the entire block of that brace. However, there is a similar caveat as above in regards to the the presence of a space. But if only 'String' was selected, additional typing of CTRL+W would eventually select the entire block.
  • Triple clicking will select the entire line.
  • Pressing CTRL+W multiple times will expand the selection, eventually selecting the entire line. (Additional hits of CTRL+W will continue expanding the selection.)
  • Double Clicking a quote mark will select the entire String literal. (You need to double click the quote mark itself, not to the left or right of it. Otherwise you will select the word enclosed by the quote.)
  • Placing your cursor inside a string literal and typing CTRL+W multiple times will select the entire String literal
  • To my knowledge, there is no behavior defined for double clicking a parenthesis.
  • To select all parameter declarations inside a set of parentheses, type CTRL+W multiple times
1

Thanks for the information, I'll have to give control-w (which is command-w on my Mac) a try.

I'm still seeing some odd behavior, and am missing some features.

Odd behavior:

- double-click on (or hit command-W just after) the } at the end of a enum or class selects just the close brace. if you hit command-W again, the line is selected. I would expect the selection to be extended to the open brace for the class/enum.

- double-clicking/command-W on the start brace of an enum/class just selects the start brace. if you hit command-W again, the entire enum/class is selected (back to the class XXX/enum XXX line). Again I would expect the brace contents to be selected in this case. In this case, clicking on/before/after the braces doesn't seem to affect the results.

- double-click on the close brace at the end of switch() selects up to the first line of the last case: (or default:) statement. I would expect the entire contents of the brace expression to be selected. Clicking on/before/afer the braces doesn't seem to make a difference.

- double-click on the start brace of a switch() selects the line that contains the switch statement itself

The fact that double-clicking on ()s has no effect seems like a bug to me, I'll file a feature request.

I just re-read your response, and maybe part of my confusion is that I have a different definition of "block of that brace" than you do. In my case I'd like to have the contents of the {} text selected in the editor. But maybe intellij defines the block as starting before the word "if" or "switch"?

1

I'll have to give control-w (which is command-w on my Mac) a try.

It's one of the most used features for me. (I use it heavily along with the introduce variable (CTRL+ALT+V), and introduce method (CTRL+ALT+M) refactorings.) Once you get use to using it, you'll wonder how you survived without it :). And it's much easier than having to reach for the mouse all the time.


- double-click on (or hit command-W just after) the } at the end of a enum or class selects just the close brace. if you hit command-W again, the line is selected. I would expect the selection to be extended to the open brace for the class/enum.

Yeah, I'm not sure why it works a little differently for a class/enum/inteface brace than for code block or method braces. It's likely simply a case that a different set of rules apply. By the way, a third typing of CTRL+W / CMD+W would select the class or enum declaration.

- double-clicking/command-W on the start brace of an enum/class just selects the start brace. if you hit command-W again, the entire enum/class is selected (back to the class XXX/enum XXX line). Again I would expect the brace contents to be selected in this case. In this case, clicking on/before/after the braces doesn't seem to affect the results.

I'd also expect CTRL+W / CMD+W to first selct the the braces and its content, and then the include the class/enum/interface declaration. This might be a bug. But for me at least, needing to select a class block is a very rare use case. So I guess I simply never noticed it.

- double-click on the close brace at the end of switch() selects up to the first line of the last case: (or default:) statement. I would expect the entire contents of the brace expression to be selected. Clicking on/before/afer the braces doesn't seem to make a difference.

- double-click on the start brace of a switch() selects the line that contains the switch statement itself

possible bugs? But again, I almost never double click. So never noticed. And a second typing of CTRL+W is no big deal.

I just re-read your response, and maybe part of my confusion is that I have a different definition of "block of that brace" than you do. In my case I'd like to have the contents of the {} text selected in the editor. But maybe intellij defines the block as starting before the word "if" or "switch"?

Correct. It identifies the opening and closing brace and its content as a block. Not the statement prior to it as a block. An additional typing of CTRL+W/CMD+W will select that statement as well. This is simply because sometime you only want the contents of the block, and not the statement.

0

Please sign in to leave a comment.