{"thread":{"id":"31625","subject":"[PATCH 2/2] gitk: Highlight first search result immediately on incremental search","startedAt":"2012-09-22T07:40:23Z","lastAt":"2012-09-23T06:59:47Z","messageCount":4,"participants":["Stefan Haller","Paul Mackerras"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"199732","messageId":"1348299625-90207-1-git-send-email-stefan@haller-berlin.de","threadId":"31625","inReplyTo":null,"subject":"[PATCH 0/2] gitk: Better highlighting of search results","fromName":"Stefan Haller","fromEmail":"stefan@haller-berlin.de","sentAt":"2012-09-22T07:40:23Z","receivedAt":"2012-09-22T07:40:23Z","isPatch":true,"sender":{"key":"stefan@haller-berlin.de","avatar":"https://avatars.githubusercontent.com/u/1225667?v=4"},"body":"Here's something that has been bugging me for a long time: when using\nthe incremental search feature, it's hard to tell what happens when\nclicking the Search button (or type Ctrl-S) repeatedly. It does have\nthe concept of a \"current\" search hit, and Ctrl-S advances to the next\none; however, you can't see it because all search hits are highlighted\nin the same way (yellow). So when there are multiple hits visible on\nthe current page, it will at some point scroll down to reveal more\nhits, but it's impossible to predict when this will happen.\n\nTo improve this, we highlight the current search in orange and the\nother ones in yellow (like Chrome does it when you search on a Web\npage).\n\nNeeds to go on top of the recent \"Synchronize highlighting in file view\nwhen scrolling diff\" patch, v3.\n\n[PATCH 1/2] gitk: Highlight current search hit in orange\n[PATCH 2/2] gitk: Highlight first search result immediately on incremental search\n"},{"id":"199731","messageId":"1348299625-90207-2-git-send-email-stefan@haller-berlin.de","threadId":"31625","inReplyTo":"1348299625-90207-1-git-send-email-stefan@haller-berlin.de","subject":"[PATCH 1/2] gitk: Highlight current search hit in orange","fromName":"Stefan Haller","fromEmail":"stefan@haller-berlin.de","sentAt":"2012-09-22T07:40:24Z","receivedAt":"2012-09-22T07:40:24Z","isPatch":true,"sender":{"key":"stefan@haller-berlin.de","avatar":"https://avatars.githubusercontent.com/u/1225667?v=4"},"body":"When searching for text in the diff, and there are multiple occurrences\nof the search string, the current one is highlighted in orange, and the\nother ones in yellow. This makes it much easier to understand what happens\nwhen you then click the Search button or hit Ctrl-S repeatedly.\n\nSigned-off-by: Stefan Haller <stefan@haller-berlin.de>\n---\n gitk | 26 +++++++++++++++++++++++---\n 1 file changed, 23 insertions(+), 3 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 16832a9..e2c0f1c 100755\n--- a/gitk\n+++ b/gitk\n@@ -2361,6 +2361,7 @@ proc makewindow {} {\n     $ctext tag conf mresult -font textfontbold\n     $ctext tag conf msep -font textfontbold\n     $ctext tag conf found -back yellow\n+    $ctext tag conf currentsearchhit -back orange\n \n     .pwbottom add .bleft\n     if {!$use_ttk} {\n@@ -2523,6 +2524,7 @@ proc makewindow {} {\n     bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}\n     bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}\n     bind $ctext <Button-1> {focus %W}\n+    bind $ctext <<Selection>> rehighlight_search_results\n \n     set maincursor [. cget -cursor]\n     set textcursor [$ctext cget -cursor]\n@@ -8039,7 +8041,6 @@ proc settabs {{firstab {}}} {\n proc incrsearch {name ix op} {\n     global ctext searchstring searchdirn\n \n-    $ctext tag remove found 1.0 end\n     if {[catch {$ctext index anchor}]} {\n \t# no anchor set, use start of selection, or of visible area\n \tset sel [$ctext tag ranges sel]\n@@ -8058,8 +8059,8 @@ proc incrsearch {name ix op} {\n \t    suppress_highlighting_file_for_current_scrollpos\n \t    highlightfile_for_scrollpos $here\n \t}\n-\tsearchmarkvisible 1\n     }\n+    rehighlight_search_results\n }\n \n proc dosearch {} {\n@@ -8087,6 +8088,7 @@ proc dosearch {} {\n \tset mend \"$match + $mlen c\"\n \t$ctext tag add sel $match $mend\n \t$ctext mark unset anchor\n+\trehighlight_search_results\n     }\n }\n \n@@ -8115,18 +8117,36 @@ proc dosearchback {} {\n \tset mend \"$match + $ml c\"\n \t$ctext tag add sel $match $mend\n \t$ctext mark unset anchor\n+\trehighlight_search_results\n+    }\n+}\n+\n+proc rehighlight_search_results {} {\n+    global ctext searchstring\n+\n+    $ctext tag remove found 1.0 end\n+    $ctext tag remove currentsearchhit 1.0 end\n+\n+    if {$searchstring ne {}} {\n+\tsearchmarkvisible 1\n     }\n }\n \n proc searchmark {first last} {\n     global ctext searchstring\n \n+    set sel [$ctext tag ranges sel]\n+\n     set mend $first.0\n     while {1} {\n \tset match [$ctext search -count mlen -- $searchstring $mend $last.end]\n \tif {$match eq {}} break\n \tset mend \"$match + $mlen c\"\n-\t$ctext tag add found $match $mend\n+\tif {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {\n+\t    $ctext tag add currentsearchhit $match $mend\n+\t} else {\n+\t    $ctext tag add found $match $mend\n+\t}\n     }\n }\n \n-- \n1.7.12.1.399.gae20e0d\n"},{"id":"199730","messageId":"1348299625-90207-3-git-send-email-stefan@haller-berlin.de","threadId":"31625","inReplyTo":"1348299625-90207-1-git-send-email-stefan@haller-berlin.de","subject":"[PATCH 2/2] gitk: Highlight first search result immediately on incremental search","fromName":"Stefan Haller","fromEmail":"stefan@haller-berlin.de","sentAt":"2012-09-22T07:40:25Z","receivedAt":"2012-09-22T07:40:25Z","isPatch":true,"sender":{"key":"stefan@haller-berlin.de","avatar":"https://avatars.githubusercontent.com/u/1225667?v=4"},"body":"When typing in the \"Search\" field, select the current search result (so\nthat it gets highlighted in orange). This makes it easier to understand\nwhat will happen if you then type Ctrl-S.\n\nSigned-off-by: Stefan Haller <stefan@haller-berlin.de>\n---\n gitk | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/gitk b/gitk\nindex e2c0f1c..39c40de 100755\n--- a/gitk\n+++ b/gitk\n@@ -8053,9 +8053,12 @@ proc incrsearch {name ix op} {\n \t}\n     }\n     if {$searchstring ne {}} {\n-\tset here [$ctext search $searchdirn -- $searchstring anchor]\n+\tset here [$ctext search -count mlen $searchdirn -- $searchstring anchor]\n \tif {$here ne {}} {\n \t    $ctext see $here\n+\t    set mend \"$here + $mlen c\"\n+\t    $ctext tag remove sel 1.0 end\n+\t    $ctext tag add sel $here $mend\n \t    suppress_highlighting_file_for_current_scrollpos\n \t    highlightfile_for_scrollpos $here\n \t}\n-- \n1.7.12.1.399.gae20e0d\n"},{"id":"199752","messageId":"20120923065947.GB15889@bloggs.ozlabs.ibm.com","threadId":"31625","inReplyTo":"1348299625-90207-1-git-send-email-stefan@haller-berlin.de","subject":"Re: [PATCH 0/2] gitk: Better highlighting of search results","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2012-09-23T06:59:47Z","receivedAt":"2012-09-23T06:59:47Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"On Sat, Sep 22, 2012 at 09:40:23AM +0200, Stefan Haller wrote:\n> Here's something that has been bugging me for a long time: when using\n> the incremental search feature, it's hard to tell what happens when\n> clicking the Search button (or type Ctrl-S) repeatedly. It does have\n> the concept of a \"current\" search hit, and Ctrl-S advances to the next\n> one; however, you can't see it because all search hits are highlighted\n> in the same way (yellow). So when there are multiple hits visible on\n> the current page, it will at some point scroll down to reveal more\n> hits, but it's impossible to predict when this will happen.\n> \n> To improve this, we highlight the current search in orange and the\n> other ones in yellow (like Chrome does it when you search on a Web\n> page).\n\nNice, thanks - applied.\n\nPaul.\n"}]}