Bug 29692 - [find/replace] Highlight all matches in editor
Summary: [find/replace] Highlight all matches in editor
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 enhancement with 8 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 64297 73972 85040 125720 207401 (view as bug list)
Depends on: 205585
Blocks:
  Show dependency tree
 
Reported: 2003-01-17 03:48 EST by Dimitar Giormov CLA
Modified: 2016-09-19 10:56 EDT (History)
18 users (show)

See Also:


Attachments
Here is a mockup of what I was thinking for the ctrl+f dialog in my first item (102.30 KB, image/jpeg)
2006-01-16 00:53 EST, calvin CLA
no flags Details
Initial effort (patches "org.eclipse.ui.workbench.texteditor") (6.71 KB, patch)
2007-07-17 18:12 EDT, Cagatay Calli CLA
no flags Details | Diff
Correct approach (works but still needs work to be completely right) (17.31 KB, patch)
2007-07-19 10:46 EDT, Cagatay Calli CLA
no flags Details | Diff
Created its own annotationType (26.12 KB, patch)
2007-07-19 17:30 EDT, Cagatay Calli CLA
no flags Details | Diff
Highlight All patch - org.eclipse.jface.text (1.53 MB, application/octet-stream)
2007-07-21 11:13 EDT, Cagatay Calli CLA
no flags Details
Highlight All patch - org.eclipse.ui.workbench.texteditor (958.99 KB, application/octet-stream)
2007-07-21 11:16 EDT, Cagatay Calli CLA
no flags Details
Highlight All source patch (29.20 KB, patch)
2007-07-24 08:21 EDT, Cagatay Calli CLA
no flags Details | Diff
searchm_obj.gif (necessary icon file) (145 bytes, image/gif)
2007-07-24 08:29 EDT, Cagatay Calli CLA
no flags Details
Highlight All source patch (updated for 20070724-0800 HEAD) (30.32 KB, patch)
2007-07-24 08:47 EDT, Cagatay Calli CLA
no flags Details | Diff
Highlight All source patch (updated for 20070724-0800 HEAD) (25.43 KB, patch)
2007-07-27 11:36 EDT, Cagatay Calli CLA
daniel_megert: review-
Details | Diff
screenshot of the search results (119.03 KB, image/png)
2016-09-19 10:50 EDT, James Neethling CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitar Giormov CLA 2003-01-17 03:48:42 EST
It would be a very good feature to have highlighted search.
To be able when searching to find all matches and highlight them, and also to 
mark them (like the warnings and the errors in the sidebar).
Comment 1 Dirk Baeumer CLA 2003-01-20 08:57:28 EST
Search matches are shown as arrows in the ruler of an editor, in the overview 
bar (right bar of an editor) and in the text itself (M4 Build). The last two 
features have to be enabled in Preferences->Java->Editor->Problem->Indication.

Please provide more information if you think this is not satisfactory.
Comment 2 Dimitar Giormov CLA 2003-02-03 06:19:33 EST
Hi again,
well I was refering to ordinary search using Ctrl-F It would be very nice if 
its posible to highlight all found matches with a diferent color. 
That way you can easyly see for example where are all usages of a variable or 
some substring.

Its something like the search in Forte for Java or CTRL-F7 in "Idea".

Best Regards,
Dimitar Giormov.
Comment 3 Dirk Baeumer CLA 2003-02-03 06:23:49 EST
Reopen and moving to JDT/Text
Comment 4 Dani Megert CLA 2004-09-15 07:26:50 EDT
*** Bug 73972 has been marked as a duplicate of this bug. ***
Comment 5 Dimitar Giormov CLA 2004-09-15 07:32:38 EDT
Hi,
I think this is fixed a long time ago. Using Ctrl-Shift-U combination.
It works fine.

best regards,
Dimitar Giormov
Comment 6 Dani Megert CLA 2004-09-15 09:07:40 EDT
Ctrl+Shift+U is not coupled to find (Ctrl+F) and only works in the Java editor
for Java elements.
Comment 7 Dani Megert CLA 2005-02-14 04:32:20 EST
*** Bug 85040 has been marked as a duplicate of this bug. ***
Comment 8 Adam Kiezun CLA 2005-02-14 09:47:15 EST
Dani,
bug 85040 was about plain text. Is there a reason why this should be a java-only
functionality?
Comment 9 Dani Megert CLA 2005-02-14 09:52:57 EST
No. This bug has to go to Platform Text.
Comment 10 Dani Megert CLA 2005-11-29 05:45:53 EST
*** Bug 64297 has been marked as a duplicate of this bug. ***
Comment 11 Martin Oberhuber CLA 2005-11-29 07:38:21 EST
I'm a little confused now.

Should platform-text provide functionality just like Java "Show Occurrences in File Quick Menu" (Ctrl+Shift+U)? This performs a Search for the word which is currently under the cursor, and scope of the current file. Search results are displayed in an extra window, with sticky markers. It appears that the original submitter of this bug is happy with Ctrl+Shift+U as it works in JDT.

Then there is the option of "Toggle Mark Occurrences" (Alt+Shift+O in JDT) which automatically marks all occurrences of the word in which the cursor currently is. This doesnt create sticky markers (they disappear as soon as the cursor is moved to a different word). It is a different, but equally helpful functionality since it doesnt require any user interaction in order to show the results.

Finally, when I read the comments here right, there was a proposal to have something totally new integrated with Search/Replace (Ctrl+F). I currently don't understand the usage scenario how this would work (use the Search Results View or not?), and what the benefit of this new operation would be compared to the others.

Could someone please clarify?
Also, would this feature be a candidate for 3.2?
Comment 12 Dani Megert CLA 2005-11-29 07:47:48 EST
Find/Replace would allow to mark all occurrences. I agree that the 'Mark Occurrence' functionality which is currently in the Java editor could help as well but I think for a normal text editor it is not that common.

>Also, would this feature be a candidate for 3.2?
No.
Comment 13 Dani Megert CLA 2006-01-13 04:53:16 EST
*** Bug 123730 has been marked as a duplicate of this bug. ***
Comment 14 calvin CLA 2006-01-16 00:51:20 EST
Hi I see 123730 is marked as a duplicate (sort of) so I thought I would give my two cents here:

1) I think there should be a "Find All" button in the ctrl+f "Find" dialog.
The find all results should populate the Search view in the same way ctrl+shift+u does except with simple arrow icons instead of read/write icons.

Reasoning: This would allow string literal and regex seaches to LIST all results in the current document which would be really useful. Useful not only for java code but many other kinds of documents long logs, xml, notes or whatever. Even MS Word can highlight all occurrences of a search. But I’m not saying that Eclipse should aspire to be Word.

2) I also think if there is a selection of length != 0 in the document and you do ctrl+shift+u it should bypass the popup (Identifier, Throwing Exception, Implementing Method) and find all occurrences of the selected character sequence in the same way that "Find All" would (except with find parameters: non-regex and case insensitive). In this case you wouldn't need to specify whether the occurrence is a read or a write in the occurrence icon. So you could just use a plain arrow.

3) It would be nice if ctrl+shift+u and mark occurrences matched java string literals too. Just to be clear, I mean the blue strings between quotes in java code.
i.e. "param" in 
someMethod(“param”);

Reasoning: This would be useful since some frameworks use Strings for some kind of mapping in which case a lot of literals are often used in code.

But I think marking occurrences of string literals should not be a enabled by default since some people may not have a need for it, may find the highlighting annoying for string literals and if it is not used it is just an extra bit of code to slow down the editor performance.

But for my needs I would be happy if just a single one of these features was implemented in the JDT.

Does any of this make sense or sound like a good idea? :)
Comment 15 calvin CLA 2006-01-16 00:53:23 EST
Created attachment 33046 [details]
Here is a mockup of what I was thinking for the ctrl+f dialog in my first item
Comment 16 Dani Megert CLA 2006-02-01 03:37:52 EST
*** Bug 125720 has been marked as a duplicate of this bug. ***
Comment 17 Mathias Hasselmann CLA 2006-03-05 10:15:29 EST
Why is the dialog that narrow in width? It's text entries are barly capable to show usual class names; not to speak about non-trivial regular expressions.
Comment 18 birmanstefan CLA 2006-06-15 13:14:19 EDT
     Highlighting all matches is a common feature in vi/vim/gvim. Most of the users I know which moved from gvim to Eclipse, asked for such a feature. In fact, this is the reason I'm posting on this thread.
     Calvin I sustain your requirements 100%.
Comment 19 Cagatay Calli CLA 2007-07-17 18:12:32 EDT
Created attachment 74001 [details]
Initial effort (patches "org.eclipse.ui.workbench.texteditor")

There are secondary things to handle on this one but here's an initial patch to have a basic "Highlight All" feature. It add annotations just like Ctrl+H annotations to Overview ruler.

As secondary issues, I mean things like the decision to implement this from org.eclipse.ui.workbench.texteditor or from org.eclipse.jface.text; as Daniel stated in Comment #9. A few changes in Text about SourceViewer might be necessary.

I also have another patch on org.eclipse.jface.text, as an effort to implement this from there. I'll also post it here when it's ready.

This patch can be summarized like this:
+ Highlights and annotates with "Highlight All" button
- Previous annotations are not removed when Ctrl+H search highlights the results. This is going to be solved in after a short period.
- Doesn't highlight ConsoleView etc. works only in the editor. This is fixed in another patch and will be merged with this patch.
Comment 20 Dani Megert CLA 2007-07-18 03:35:45 EDT
Hi Cagatay,

I tried the patch but it does not seem to highlight all matches (it seems to miss the first occurrence). Here some detailed feedback:

- The FindReplaceDialog must communicate only via find replace target. Setting
  a source viewer completely breaks the current abstractions. You need to add
  a IFindReplaceTargetExtension4 for this new feature.

- The patch breaks layering by accessing stuff from a plug-in that it doesn't
  require (the search annotation type). The feature must also work for those
  that don't want the Search plug-in, e.g. an RCP application.

- The highlighting stays too long. Maybe closing the dialog should also remove
  them. Another idea might be to use a push button with state: if pressed, the
  results are highlighted and if depressed they are cleared.

- source code: make sure you add Javadoc everywhere, add the @since 3.4 tag
  on new members, add yourself to the copyright notes, update copyright date
  if needed, honor existing formatting, etc.
Comment 21 Cagatay Calli CLA 2007-07-19 10:46:26 EDT
Created attachment 74158 [details]
Correct approach (works but still needs work to be completely right)

I've produced another patch in the light of Daniel's last comment. I hope the only remaining work is summarized as follows:

TODO:
- Create own annotation type
- Add raw highlighing for targets that don't support annotations
- Move status message NLS strings of "highligh all" to EditorMessages.

BEHAVIOUR:
* "Highlight All" toggle in Find/Replace dialog highlights/clears annotations.
* If dialog is closed, annotations are cleared.

PATCHES:

org.eclipse.jface.text
+ IFindReplaceTargetExtension4
* TextViewer

org.eclipse.ui.workbench.texteditor 
* FindReplaceDialog
* FindReplaceTarget
Comment 22 Cagatay Calli CLA 2007-07-19 17:30:18 EDT
Created attachment 74197 [details]
Created its own annotationType

* Create own annotation type - DONE

I've also created an Update Site for those who want to try in a clean Eclipse install (since its still experimental):

Update Site:
http://user.ceng.metu.edu.tr/~e1394824/HighlightAllUpdateSite/site.xml

You may not like the highlight color. :)

I'm also attaching my work as a patch but it doesn't include marker icon (although I've added the icon, I couldn't include it in the patch) so you need to get it from the Update Site if you want to also see a marker on the left ruler.
Comment 23 Dennis Ballance CLA 2007-07-20 01:01:36 EDT
Cagatay, 

I'm thrilled you're tackling this! I tried the update url you supplied, and it works well. Curiously, however, it also disables my WST HTML editor (I haven't tried the others) -- the editor disappears completely from my list of available editors. If I disable HighlightAll and restart, I once again can use the WST editor. Any idea what's going on there? I looked in my log and couldn't see anything of relevance.
Comment 24 Cagatay Calli CLA 2007-07-20 02:46:21 EDT
I created the update site and the corresponding feature project in a hurry so I think that I may have made a mistake about versioning my build of jface.text and workbench.texteditor and this may be the explanation. 
The update site was just for test purposes. Don't worry I'm going to produce a final version without any problems soon.
Comment 25 Dennis Ballance CLA 2007-07-20 02:47:33 EDT
Ok - I did see warnings about version mismatches on both of those, so that would fit.
Comment 26 Cagatay Calli CLA 2007-07-20 13:14:57 EDT
Dennis the problem with WST HTML editor was because my patch was on jface.text and workbench.texteditor components from Eclipse HEAD. (version: 3.4.0.qualifier) WST requires [3.3.0,3.4.0) so WST doesn't accept my jface.text.

I wanted to inform you about this small issue. I'm going to put the version that uses 3.3.0 components to the update site soon.
Comment 27 Philippe Ombredanne CLA 2007-07-20 16:57:21 EDT
Awesome, a great opportunity to kill an old feature request!
Comment 28 Cagatay Calli CLA 2007-07-21 11:13:13 EDT
Created attachment 74294 [details]
Highlight All patch - org.eclipse.jface.text

patch for 20070717-0800 Eclipse HEAD.

Zip files include
* org.eclipse.jface.text
* org.eclipse.ui.workbench.texteditor
projects.

Externalized "highlight all" related strings (now in EditorMessages like other Find/Replace messages).

- Tried adding raw highlighting (w/o annotations) TextViewer objects that are not an instance of SourceViewer. I could have added a method like public void setBackgroundColor(Color color, int start, int length, boolean controlRedraw) like TextViewer#setTextColor(), however I saw that setTextColor() method was logically wrong (removed other styling when foreground text color is set with this method).

I wanted to implement this "raw highlighting" for "else" part in 5427th line in org.eclipse.jface.text.TextViewer class. However, it seems that, that "else" part has no corresponding scenario in the real world either.

Here is that part ("else" part reflects what to do if a corresponding setBackgroundColor() method existed in API):

if(isAnnotatible()){
					AnnotationModel model = (AnnotationModel) ((ISourceViewer) TextViewer.this).getAnnotationModel();
					Annotation findAnnotation = new Annotation("org.eclipse.jface.text.find",true,adapter.subSequence(widgetPos, widgetPos+length).toString()); //$NON-NLS-1$
					Position position = new Position(widgetPos,length);
					model.addAnnotation(findAnnotation, position);
				}
				else {
					// TODO Add raw highlighing for targets that don't support annotations
//					Color highlight = new Color(getTextWidget().getDisplay(),255,255,0);
//					setBackgroundColor(highlight, widgetPos, length, false);
				}

Other than this issue, I believe the patch is complete.

An addition to implement for "Highlight All" is showing "soft matches" which are case-insensitive matches in a different color, whole word matches in a stronger color etc. like in Ctrl+H search highlighting. I'll work on it.
Comment 29 Cagatay Calli CLA 2007-07-21 11:16:37 EDT
Created attachment 74295 [details]
Highlight All patch - org.eclipse.ui.workbench.texteditor

patch for 20070717-0800

* zip includes org.eclipse.ui.workbench.texteditor project
Comment 30 Dani Megert CLA 2007-07-24 04:21:49 EDT
Regarding the version number issue: this is clearly a WST bug they should have something like:
  org.eclipse.ui.workbench.texteditor;bundle-version="[3.3.0,4.0.0)"
  etc.

Please DO NOT create plug-ins that have the same version number as the one from the official release (e.g. 3.3.0). As you can see from the problems with your initial "patch" you can cause trouble for your clients. Even if you name it 3.3.0 it might then resolve but actually activate the wrong instance of that plug-in. I therefore marked your two attachments as obsolete.

Please attach valid patches if you expect us to review them.
Comment 31 Dani Megert CLA 2007-07-24 04:24:58 EDT
>Please attach valid patches if you expect us to review them.
i.e. not ZIP(s) with the project(s) but one single patch file created bia Team > Create Patch...
Comment 32 Nitin Dahyabhai CLA 2007-07-24 04:49:31 EDT
(In reply to comment #26)
I think you mean the org.eclipse.wst.common.ui plug-in it depends on, which because it's not API clean is intentionally using a narrower range of [3.2.0,3.4.0).
Comment 33 Dani Megert CLA 2007-07-24 05:14:20 EDT
You mean it uses internal API from Text? In that case the version is OK. The "patch" should use something like 3.3.100.zzzMyPatch then to avoid problems described in comment 30.
Comment 34 Cagatay Calli CLA 2007-07-24 08:21:39 EDT
Created attachment 74445 [details]
Highlight All source patch

(without necessary icon file "/icons/full/obj16/searchm_obj.gif" in org.eclipse.jface.text )

I'm sorry about wrong attachments Daniel. I hope this is the correct way, I'm also attaching necessary icon file.

Since it's intended to be a source patch, versioning discussion doesn't matter right? It's a patch on current HEAD.
Comment 35 Cagatay Calli CLA 2007-07-24 08:29:42 EDT
Created attachment 74447 [details]
searchm_obj.gif (necessary icon file)

should reside in
<org.eclipse.jface.text plugin folder>/icons/full/obj16/searchm_obj.gif
Comment 36 Dani Megert CLA 2007-07-24 08:32:44 EDT
>Since it's intended to be a source patch, versioning discussion doesn't matter
>right?
Right.
Comment 37 Cagatay Calli CLA 2007-07-24 08:47:20 EDT
Created attachment 74449 [details]
Highlight All source patch (updated for 20070724-0800 HEAD)

updated the patch for today's HEAD
Comment 38 Cagatay Calli CLA 2007-07-27 11:36:07 EDT
Created attachment 74801 [details]
Highlight All source patch (updated for 20070724-0800 HEAD)

I'm sorry I made a mistake in my last attachment.
Here's the correct patch for 20070724-0800 HEAD.
Comment 39 Dani Megert CLA 2007-08-03 05:47:34 EDT
JFace Text knows nothing about extension points (i.e. must not get a plugin.xml) and even if it would, you cannot reference an extension point that's in a much higher plug-in.

Here some other comments in no particula order:
- adding/removing is quite slow (looks sluggish) -> you have to do this batched 
  in one call, see IAnnotationModelExtension.replaceAnnotations(*) for details. 
  Also make sure not to call clear and then add/highlight. This also has to
  take place in a single replaceAnnotations(*) call
- you need to attach the binary resouces separately. CVS patch format cannot
  deal with them :-(
- if the Find text is altered we should remove the highlightings and reset
  the button
- I think the dialog would look nicer if the new button is alligned to the right
- use a more descriptive name for the annotation type, e.g. "Text Matches" as
  it is not sure that they are highlighted anymore once the user changes the
  preferences
- don't show it in the vertical ruler per default.
- never touch files you don't alter (e.g. the change to the copyright
  in the build.properties is not OK)
- always add a mnemonic if you add a UI element that can get focus
- referring to ISourceViewer inside TextViewer is a no go. A possible
  solution might be to extract the FindReplaceTarget into
  its own class (TextViewerFindReplaceTarget) and move it into 
  org.eclipse.jface.internal.text. You can then subclass it to
  implement a SourceViewerFindReplaceTarget.
- the new methods in IFindReplaceTargetExtension4 must mention that they
  are restricted to ISourceViewer and they should throw an 
  IllegalStateException if this is violated
- the dialog must disable the highlight button if the target is not
  an ISourceViewer
Comment 40 Dani Megert CLA 2007-10-25 02:48:13 EDT
*** Bug 207401 has been marked as a duplicate of this bug. ***
Comment 41 Henrik Gustafsson CLA 2010-07-07 06:19:10 EDT
Another use-case for highlighting all matches would be when using incremental find. The ability to see what possible matches are in the current file would be great. Like is works by default in Emacs (on Debian at least)
Comment 42 Andrei ILIE CLA 2012-11-17 16:37:59 EST
up :)
Comment 43 Andrey Loskutov CLA 2016-09-19 09:11:34 EDT
Can someone summarize the state of this bug/patch? I've read through the comments but I'm completely lost because I don't know which comment actually describes *requirements* and which *solutions*. *What* was proposed? *What* was implemented? Where is the patch? Is this request still relevant? Do we still need it? See also bug 501471 with a similar request.

@Cagatay Calli: are you still there? If yes, do you mind to provide a Gerrit patch (see https://wiki.eclipse.org/Platform_UI/How_to_Contribute)?
Comment 44 James Neethling CLA 2016-09-19 10:50:39 EDT
Created attachment 264257 [details]
screenshot of the search results

screenshot highlighting the search results for the search term 'link' in an example file. The search term is highlighted with a background color.
Comment 45 James Neethling CLA 2016-09-19 10:56:27 EDT
(In reply to Andrey Loskutov from comment #43)
> Can someone summarize the state of this bug/patch? I've read through the
> comments but I'm completely lost because I don't know which comment actually
> describes *requirements* and which *solutions*. *What* was proposed? *What*
> was implemented? Where is the patch? Is this request still relevant? Do we
> still need it? See also bug 501471 with a similar request.
> 
> @Cagatay Calli: are you still there? If yes, do you mind to provide a Gerrit
> patch (see https://wiki.eclipse.org/Platform_UI/How_to_Contribute)?

Can't comment on the others, by my original request bug 73972), which was logged as dup. (comment 4) was suggesting that the "find" dialog would also highlight all the occurrences of the search term in the file, allowing for easy navigation to the searched term.

Dirks comments in comment 2 indicates that arrows are added to the ruler which helps. This is sufficient for my purposes.

bug 501471 has similar BEHAVIOUR, but the trigger is not the "find" operation, it is just the default text editor behavior. Notepad++ is a great example of this behaviour. bug 501471 is not a dup, but related.

I've just realised that the file search (ctrl+h) provides the behavior that I was looking for except for all files - see Attachment 264257 [details] where the search term is highlighted in the file. 

I haven't tried any of the updates that were suggested.

Hope that this helps.