git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] gitk: Better highlighting of search results
@ 2012-09-22  7:40 Stefan Haller
  2012-09-22  7:40 ` [PATCH 1/2] gitk: Highlight current search hit in orange Stefan Haller
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stefan Haller @ 2012-09-22  7:40 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git

Here's something that has been bugging me for a long time: when using
the incremental search feature, it's hard to tell what happens when
clicking the Search button (or type Ctrl-S) repeatedly. It does have
the concept of a "current" search hit, and Ctrl-S advances to the next
one; however, you can't see it because all search hits are highlighted
in the same way (yellow). So when there are multiple hits visible on
the current page, it will at some point scroll down to reveal more
hits, but it's impossible to predict when this will happen.

To improve this, we highlight the current search in orange and the
other ones in yellow (like Chrome does it when you search on a Web
page).

Needs to go on top of the recent "Synchronize highlighting in file view
when scrolling diff" patch, v3.

[PATCH 1/2] gitk: Highlight current search hit in orange
[PATCH 2/2] gitk: Highlight first search result immediately on incremental search

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] gitk: Highlight current search hit in orange
  2012-09-22  7:40 [PATCH 0/2] gitk: Better highlighting of search results Stefan Haller
@ 2012-09-22  7:40 ` Stefan Haller
  2012-09-22  7:40 ` [PATCH 2/2] gitk: Highlight first search result immediately on incremental search Stefan Haller
  2012-09-23  6:59 ` [PATCH 0/2] gitk: Better highlighting of search results Paul Mackerras
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Haller @ 2012-09-22  7:40 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git

When searching for text in the diff, and there are multiple occurrences
of the search string, the current one is highlighted in orange, and the
other ones in yellow. This makes it much easier to understand what happens
when you then click the Search button or hit Ctrl-S repeatedly.

Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
---
 gitk | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/gitk b/gitk
index 16832a9..e2c0f1c 100755
--- a/gitk
+++ b/gitk
@@ -2361,6 +2361,7 @@ proc makewindow {} {
     $ctext tag conf mresult -font textfontbold
     $ctext tag conf msep -font textfontbold
     $ctext tag conf found -back yellow
+    $ctext tag conf currentsearchhit -back orange
 
     .pwbottom add .bleft
     if {!$use_ttk} {
@@ -2523,6 +2524,7 @@ proc makewindow {} {
     bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
     bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
     bind $ctext <Button-1> {focus %W}
+    bind $ctext <<Selection>> rehighlight_search_results
 
     set maincursor [. cget -cursor]
     set textcursor [$ctext cget -cursor]
@@ -8039,7 +8041,6 @@ proc settabs {{firstab {}}} {
 proc incrsearch {name ix op} {
     global ctext searchstring searchdirn
 
-    $ctext tag remove found 1.0 end
     if {[catch {$ctext index anchor}]} {
 	# no anchor set, use start of selection, or of visible area
 	set sel [$ctext tag ranges sel]
@@ -8058,8 +8059,8 @@ proc incrsearch {name ix op} {
 	    suppress_highlighting_file_for_current_scrollpos
 	    highlightfile_for_scrollpos $here
 	}
-	searchmarkvisible 1
     }
+    rehighlight_search_results
 }
 
 proc dosearch {} {
@@ -8087,6 +8088,7 @@ proc dosearch {} {
 	set mend "$match + $mlen c"
 	$ctext tag add sel $match $mend
 	$ctext mark unset anchor
+	rehighlight_search_results
     }
 }
 
@@ -8115,18 +8117,36 @@ proc dosearchback {} {
 	set mend "$match + $ml c"
 	$ctext tag add sel $match $mend
 	$ctext mark unset anchor
+	rehighlight_search_results
+    }
+}
+
+proc rehighlight_search_results {} {
+    global ctext searchstring
+
+    $ctext tag remove found 1.0 end
+    $ctext tag remove currentsearchhit 1.0 end
+
+    if {$searchstring ne {}} {
+	searchmarkvisible 1
     }
 }
 
 proc searchmark {first last} {
     global ctext searchstring
 
+    set sel [$ctext tag ranges sel]
+
     set mend $first.0
     while {1} {
 	set match [$ctext search -count mlen -- $searchstring $mend $last.end]
 	if {$match eq {}} break
 	set mend "$match + $mlen c"
-	$ctext tag add found $match $mend
+	if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
+	    $ctext tag add currentsearchhit $match $mend
+	} else {
+	    $ctext tag add found $match $mend
+	}
     }
 }
 
-- 
1.7.12.1.399.gae20e0d

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] gitk: Highlight first search result immediately on incremental search
  2012-09-22  7:40 [PATCH 0/2] gitk: Better highlighting of search results Stefan Haller
  2012-09-22  7:40 ` [PATCH 1/2] gitk: Highlight current search hit in orange Stefan Haller
@ 2012-09-22  7:40 ` Stefan Haller
  2012-09-23  6:59 ` [PATCH 0/2] gitk: Better highlighting of search results Paul Mackerras
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Haller @ 2012-09-22  7:40 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git

When typing in the "Search" field, select the current search result (so
that it gets highlighted in orange). This makes it easier to understand
what will happen if you then type Ctrl-S.

Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
---
 gitk | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gitk b/gitk
index e2c0f1c..39c40de 100755
--- a/gitk
+++ b/gitk
@@ -8053,9 +8053,12 @@ proc incrsearch {name ix op} {
 	}
     }
     if {$searchstring ne {}} {
-	set here [$ctext search $searchdirn -- $searchstring anchor]
+	set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
 	if {$here ne {}} {
 	    $ctext see $here
+	    set mend "$here + $mlen c"
+	    $ctext tag remove sel 1.0 end
+	    $ctext tag add sel $here $mend
 	    suppress_highlighting_file_for_current_scrollpos
 	    highlightfile_for_scrollpos $here
 	}
-- 
1.7.12.1.399.gae20e0d

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] gitk: Better highlighting of search results
  2012-09-22  7:40 [PATCH 0/2] gitk: Better highlighting of search results Stefan Haller
  2012-09-22  7:40 ` [PATCH 1/2] gitk: Highlight current search hit in orange Stefan Haller
  2012-09-22  7:40 ` [PATCH 2/2] gitk: Highlight first search result immediately on incremental search Stefan Haller
@ 2012-09-23  6:59 ` Paul Mackerras
  2 siblings, 0 replies; 4+ messages in thread
From: Paul Mackerras @ 2012-09-23  6:59 UTC (permalink / raw)
  To: Stefan Haller; +Cc: git

On Sat, Sep 22, 2012 at 09:40:23AM +0200, Stefan Haller wrote:
> Here's something that has been bugging me for a long time: when using
> the incremental search feature, it's hard to tell what happens when
> clicking the Search button (or type Ctrl-S) repeatedly. It does have
> the concept of a "current" search hit, and Ctrl-S advances to the next
> one; however, you can't see it because all search hits are highlighted
> in the same way (yellow). So when there are multiple hits visible on
> the current page, it will at some point scroll down to reveal more
> hits, but it's impossible to predict when this will happen.
> 
> To improve this, we highlight the current search in orange and the
> other ones in yellow (like Chrome does it when you search on a Web
> page).

Nice, thanks - applied.

Paul.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-23  7:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-22  7:40 [PATCH 0/2] gitk: Better highlighting of search results Stefan Haller
2012-09-22  7:40 ` [PATCH 1/2] gitk: Highlight current search hit in orange Stefan Haller
2012-09-22  7:40 ` [PATCH 2/2] gitk: Highlight first search result immediately on incremental search Stefan Haller
2012-09-23  6:59 ` [PATCH 0/2] gitk: Better highlighting of search results Paul Mackerras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).