Closed Bug 240432 Opened 20 years ago Closed 11 years ago

Highlight search terms

Categories

(Firefox :: Search, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX
Future

People

(Reporter: bart, Unassigned)

References

Details

Attachments

(1 file)

The ability to highlight search terms in search results.  So when I execute a
search using the Google searchbox I would like the search terms to be highlighted.

One way to implement this feature would be to replace the Find in this Page with
Highlight, so the user could click on the pulldown to highlight the search terms
(and do a highlight operation on an arbitrary string).
taking
Status: NEW → ASSIGNED
OS: MacOS X → All
Hardware: Macintosh → All
Target Milestone: --- → Firefox0.9
Flags: blocking1.0+
Priority: -- → P3
Target Milestone: Firefox0.9 → Firefox1.0
Find now has highlight.  It would be nice if there were a way to highlight words
and phrases from the Google search that brought me to the page.  This would
require parsing Google searches and being able to highlight mutliple phrases in
different colors.
Unfortunately, the way this is implemented in Netscape7.2 is very disturbing and
sets a very bad precedent. It changes the author's DOM by wrapping all matches
with styled <span>, i.e.:

<span style="background-color: yellow;" class="NetscapeToolbarHighlight">
  ...highlighted text...
</span>

And as you keep hitting Highlight with different terms, all those <span>s hang
there in the DOM indefinitely (use view-selection-source to see). Thus scripts
that build on assumptions on their DOM will be broken or become very fragile.

There are things in the back-end that can assist with highlighting. For example,
one can find all the matches, create ranges and select them on the go after
setting the .maintainSelection flag or something (or the code can be extended to
select several ranges at once to mee UI demands). I am speaking from memory. I
seem to recollect that the selection code has the ability of selecting
discontinuous ranges: one word here, another there, etc.
>And as you keep hitting Highlight with different terms, all those <span>s hang
>there in the DOM indefinitely.

Correction: the next Highlights remove the previous ones.
Yeah, this is far from good, but doing this right is non-trivial. We'd need a
way to do some special "selection" when the found words are hilighted and then
color that selection like we do when a user selects text. Different colour
though, and not the same selection etc.
I am attaching an image that illustrates the retention of multiple matches and
a different color (this is the same color used in find-as-you-type by just
setting
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ATTENTION)
rather than the default SELECTION_ON that gives the bluish selection);

The patch to produce this screenshot is the three-liners given below. It
illustrates how a |FindAll()| can be done if some UI people are interested. The
idea is not to clear the previous match (as |FindNext()| does). The selection
code knows how to handle discontinuous selections. The catch, however, is that
if one clicks somewhere in the content area, all the matches disappear...

--- nsWebBrowserFind-orig.cpp	2004-08-20 14:28:46.000000000 +1000
+++ nsWebBrowserFind.cpp	2004-08-20 14:17:06.000000000 +1000
@@ -446,11 +446,12 @@
     tcFrame->GetSelectionContr(getter_AddRefs(selCon));
   }

-  selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
+//XXXrbs  selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
+  selCon->SetDisplaySelection(nsISelectionController::SELECTION_ATTENTION);
   selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
     getter_AddRefs(selection));
   if (selection) {
-    selection->RemoveAllRanges();
+//XXXrbs    selection->RemoveAllRanges();
     selection->AddRange(aRange);

     if (tcFrame) {
@@ -794,7 +795,7 @@
     if (NS_SUCCEEDED(rv) && foundRange)
     {
	 *aDidFind = PR_TRUE;
-	 sel->RemoveAllRanges();
+//XXXrbs	 sel->RemoveAllRanges();
	 SetSelectionAndScroll(aWindow, foundRange);
     }
Just wanted to add one more observation. If you highlight all the occurences by
clicking on "Highlight" button in find toolbar and then again click on same
button, the highligheted text becomes normal. But if the page contains text
field/area and that area has matching text this still remains highlited

eg. On this page searc for "on", then highlight & unhighlight it. "On" in QA
Contact text box is still shown in yellow colour. You need to refresh the page
to get it back to norma
Bug 259986 and Bug 260203 are related to comment #7, they are probably
dublicates of this bug
Comment 7 has nothing to do with this bug.
p4 priority - not a blocker. if a fully reviewed patch materializes, please
nominate for aviary approval. 
Flags: blocking-aviary1.0+ → blocking-aviary1.0-
Re: comment 6

> The catch, however, is that
> if one clicks somewhere in the content area, all the matches disappear...

Iterating on the approach suggested earlier. The disappearance problem could be
resolved by putting the find-all terms in a different selection type (e.g.,
SELECTION_HIGHLIGHT), which isn't hidden away when the user merely clicks. Much
like what you guys did in the inline spell checker (attachment 171212 [details] and bug
278312).
QA Contact: bugzilla → toolbars
The Internet Explorer also has this bug.
Severity: normal → enhancement
Assignee: mscott → nobody
Status: ASSIGNED → NEW
Component: Toolbars → Search
Priority: P4 → --
QA Contact: toolbars → search
Target Milestone: Firefox1.0 → ---
Version: unspecified → Trunk
Target Milestone: --- → Future
Depends on: 263683
No longer depends on: 256773
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: