Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 181931

Summary: double-click after opening brace does not select all block
Product: [Eclipse Project] Platform Reporter: Eric Jodet <eric_jodet>
Component: SWTAssignee: Felipe Heidrich <eclipse.felipe>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: alex.blewitt, bokowski, daniel_megert, Olivier_Thomann, philippe_mulet, Silenio_Quarti, snorthov, thatnitind, Tod_Creasey
Version: 3.3   
Target Milestone: 3.3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
screen shot none

Description Eric Jodet CLA 2007-04-11 08:58:24 EDT
Version: 3.3.0
Build id: I20070410-1043

J2RE 5.0 IBM J9 2.3 Windows XP x86-32 build j9vmwi3223-2007020

test scenario:
- open a Java file
- at the beginning of a method, or try block, place the cursor after the opening brace {
- double click

--> only the current line gets selected, whereas I expect the whole block to be selected.

this works OK with an M6 build
Comment 1 Eric Jodet CLA 2007-04-11 08:58:55 EDT
Created attachment 63492 [details]
screen shot
Comment 2 Dani Megert CLA 2007-04-11 10:23:11 EDT
This is caused by StyledText.handleMouseDown which cuts the offset provided by the MovementListener to the end of the current line:
   end = Math.min(lineEnd, getWordNext(start, SWT.MOVEMENT_WORD_END));

This breaks all contributed double-click listeners that spawn a line.

NOTE: same is true for getting the previous offset:
   start = Math.max(lineOffset, getWordPrevious(offset, SWT.MOVEMENT_WORD_START));

StyledText should simply lift that restriction.
Comment 3 Dani Megert CLA 2007-04-11 10:25:31 EDT
Steve, I've targeted this to 3.3 since we need being fixed but better would be to have a fix asap since this impacts daily work for those that use double-click to select code blocks. The fix seems to be trivial.
Comment 4 Olivier Thomann CLA 2007-04-12 10:10:15 EDT
It also doesn't work when double-clicking after closing brace. This is a major drawback in the Java editor.
Comment 5 Philipe Mulet CLA 2007-04-12 11:52:54 EDT
I am suffering as well, and even blamed Dani by mistake...
Comment 6 Dani Megert CLA 2007-04-13 10:07:43 EDT
*** Bug 182322 has been marked as a duplicate of this bug. ***
Comment 7 Dani Megert CLA 2007-04-13 10:08:45 EDT
Here's another dup.

Steve, could you fix this for the next I-build? The change shouldn't be too hard, the only thing to do is ensuring that triple-click still selects the line.
Comment 8 Carolyn MacLeod CLA 2007-04-13 14:26:57 EDT
From Olivier: It works fine in I20070403-1110, but the triple click doesn't work as expected. I believe the problem was introduced when trying to fix the issue with triple click.

For info, the triple-click bug that was fixed in this time frame is: bug 14654.

Investigating...
Comment 9 Carolyn MacLeod CLA 2007-04-13 16:28:45 EDT
OK, I changed the 2 lines of code in handleMouseDown() to be the following:
  start = Math.max(0, getWordPrevious(offset, SWT.MOVEMENT_WORD_START));
  end = Math.min(getCharCount(), getWordNext(start, SWT.MOVEMENT_WORD_END));

start and end do need to be protected in case an application returns an incorrect value in getWordPrevious or getWordNext, but it seems that lineOffset and lineEnd are too restrictive. Clamping the values to be between 0 and getCharCount() lets them be valid values anywhere in the document.

This is now released to HEAD and will be in Tuesday's I-build.

I am not going to mark the bug fixed, though, until Felipe verifies the code when he gets back from vacation. Felipe owns StyledText, and he may have had some reason that I don't know about to max with lineOffset and min with lineEnd.

Dani, please test the next I-build really well in this area. (or test the N-build on Monday if you want to make sure it's ok for Tuesday's I-build).

Felipe, please verify that this fix didn't break something else, and if it's ok then please mark the bug fixed.

Thanks,
Car
Comment 10 Dani Megert CLA 2007-04-16 04:39:09 EDT
Verifified the fix and double and triple-click in N20070416-0010. SWT rules!
Comment 11 Dani Megert CLA 2007-04-23 15:36:53 EDT
*** Bug 183649 has been marked as a duplicate of this bug. ***
Comment 12 Felipe Heidrich CLA 2007-04-30 12:31:47 EDT
I can't recall why I needed this range test here. Apparently it only needs to compute the line start and line end for triple click.

Since everything is working I'll not change the code.