Bug 27996 - [find/replace] Make shift-enter search backwards in Find/Replace dialog
Summary: [find/replace] Make shift-enter search backwards in Find/Replace dialog
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Rajesh CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 65679
Blocks:
  Show dependency tree
 
Reported: 2002-12-09 22:58 EST by Ed Burnette CLA
Modified: 2010-09-14 07:40 EDT (History)
4 users (show)

See Also:


Attachments
Patch contains fix and test (11.62 KB, patch)
2010-08-17 06:37 EDT, Rajesh CLA
daniel_megert: review-
Details | Diff
Patch 27996 (12.24 KB, patch)
2010-08-17 16:39 EDT, Rajesh CLA
daniel_megert: iplog+
daniel_megert: review+
Details | Diff
Patch contains test only (6.94 KB, patch)
2010-08-19 13:21 EDT, Rajesh CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Burnette CLA 2002-12-09 22:58:36 EST
If you open the Find dialog (^F) and type a string and hit return it searches 
forwards (assuming you have the Forwards option checked). This is a request to 
make it search *backwards* if you are holding the shift key when you hit 
return. That way if you're like me and hit return too many times you can shift-
return to back up to the one you want. For precedents see TextPad and 
VisualStudio.
Comment 1 Dani Megert CLA 2003-09-24 09:03:51 EDT
Marking as remind. Will be activated when bug 21464 is fixed.
Comment 2 Ed Burnette CLA 2004-09-18 22:36:38 EDT
What's the status on this one, can it be reopened? I don't quite understand 
the relationship with bug 21464, is it something to do with the SHIFT mask not 
being available to distinguish ENTER from SHIFT+ENTER? The OS should provide 
it, at least on Win32, because the two other editors I mention supported it.
Comment 3 Dani Megert CLA 2004-09-20 05:21:30 EDT
The relationship is that the modifier is not set (see bug 21464).
Comment 4 Billy Biggs CLA 2005-05-29 14:32:32 EDT
This bug really depends on bug 65679.  Bug 21464 is specifically about the
detail in the SelectionEvent of a scrollbar on GTK+.
Comment 5 Dani Megert CLA 2007-06-22 09:59:45 EDT
Get rid of deprecated state.
Comment 6 Dani Megert CLA 2007-06-22 10:04:54 EDT
.
Comment 7 Markus Keller CLA 2007-08-28 12:57:30 EDT
Why is this invalid? Shift+Enter can easily be detected in the Combo by listening for the Traverse event.

Shift+Click on "Find" button to search backwards is not easy to implement due to bug 65679, but that's not requested in this bug.
Comment 8 Dani Megert CLA 2007-08-29 03:07:10 EDT
Sorry but bug 65679 is exactly describing the problem: the stateMask is not set no matter whether I click the button or invoke it via pressing the Return key (or whatever triggers the selection event on the default button - this can be platform dependent).

I won't work around this. Your suggestion is handling one specific case i.e. when the selection is still on the text field. It would be pretty unexpected that it doesn't work when the selection is on a checkbox or anywhere else and I won't add a listener to every control in the dialog.
Comment 9 Dani Megert CLA 2007-08-29 03:08:37 EDT
Or we get bug 71538 which allows me to query the state myself.
Comment 10 Rajesh CLA 2010-08-17 06:37:16 EDT
Created attachment 176772 [details]
Patch contains fix and test
Comment 11 Dani Megert CLA 2010-08-17 10:04:25 EDT
>Created an attachment (id=176772) [details] [diff]
>Patch contains fix and test
Initial comments on the patch can be found in bug 319560. Here some more comments after detailed review and testing:

Looking at the code it looks like incremental search is broken now: it always searches backwards. Testing confirms that.

Since we also use 'Shift' on the 'Find' button we also have to do the same for 'Replace/Find'. This is currently not the case.

The test works but it is a very fragile test since it relies on events. If you that that you need to add more safety to it. E.g. clicking on the host workspace after lunching the test lets it fail. Also, the new code uses spaces for indentation at some places. Please always use tabs for indentation.

>@param forwardSearch the search direction
It's usually good to use/copy the same pattern as already done in the file. However, for boolean parameters we now always explicitly mention true/false using the following pattern:
@param forwardSearch <code>true</code> if searching forwards, <code>false</code> otherwise

>e.stateMask == SWT.SHIFT) ? !isForwardSearch() : isForwardSearch()
Less verbose: e.stateMask == SWT.SHIFT ^ isForwardSearch()

Also note that there should be an empty line before the Javadoc parameters.
Comment 12 Rajesh CLA 2010-08-17 16:39:09 EDT
Created attachment 176845 [details]
Patch 27996

(In reply to comment #11)
> >Created an attachment (id=176772) [details] [details] [diff]
> >Patch contains fix and test
> Initial comments on the patch can be found in bug 319560. Here some more
> comments after detailed review and testing:
> 
> Looking at the code it looks like incremental search is broken now: it always
> searches backwards. Testing confirms that.

The last change to use 'forwardSearch' as parameter name caused this. My bad. Fixed.

> 
> Since we also use 'Shift' on the 'Find' button we also have to do the same for
> 'Replace/Find'. This is currently not the case.

Implemented.

> 
> The test works but it is a very fragile test since it relies on events. If you
> that that you need to add more safety to it. E.g. clicking on the host
> workspace after lunching the test lets it fail. Also, the new code uses spaces
> for indentation at some places. Please always use tabs for indentation.

While, forcing focus before generating events did improve reliability, it still didn't seem good enough. Replaced posting of events with direct calls.

> 
> >@param forwardSearch the search direction
> It's usually good to use/copy the same pattern as already done in the file.
> However, for boolean parameters we now always explicitly mention true/false
> using the following pattern:
> @param forwardSearch <code>true</code> if searching forwards,
> <code>false</code> otherwise

Done.

> 
> >e.stateMask == SWT.SHIFT) ? !isForwardSearch() : isForwardSearch()
> Less verbose: e.stateMask == SWT.SHIFT ^ isForwardSearch()

neat idea.

> 
> Also note that there should be an empty line before the Javadoc parameters.
Comment 13 Dani Megert CLA 2010-08-19 02:09:47 EDT
> 
> Also note that there should be an empty line before the Javadoc parameters.
Not done ;-)

Committed runtime code to HEAD with above fix.


Test:
=====
Works fine. There are some minor issues:
1. setUp/tearDown runs for each test. Since we only use the big setup for one
   test, we should not punish the other tests with additional work.

2. When creating UI stuff, you should always close or dispose them when no
   longer needed. In your patch all viewers accumulate until the whole workbench
   goes down.

>private Display display;
Not using 'f' prefix for fields, but the field is overkill here anyway.

>Please always use tabs for indentation.
Not done.

Next patch only needs test code.
Comment 14 Rajesh CLA 2010-08-19 13:21:32 EDT
Created attachment 177028 [details]
Patch contains test only
Comment 15 Dani Megert CLA 2010-08-20 03:57:34 EDT
Committed tests to HEAD.

Rajesh, there was one minor issue: if someone adds a new test that doesn't need to open the Find/Replace dialog (or closes it in its tests), then it would result in an NPE during tear down.
Comment 16 Markus Keller CLA 2010-08-20 13:30:39 EDT
The test failed on GTK because
- shells activation events are only sent when the event loop is run, so the dialog shell was always null
- bug 323272 in SWT (traverse event notification too late)

I've released workarounds for this to HEAD.
Sorry Dani, I've accidentally used your connection on the build machine.
Comment 17 Deepak Azad CLA 2010-09-14 07:40:20 EDT
Verified for 3.7M2 on Linux with I20100914-0100.