git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Max Kirillov <max@max630.net>
To: Stefan Haller <lists@haller-berlin.de>
Cc: Paul Mackerras <paulus@samba.org>, git@vger.kernel.org
Subject: [RFC] HACK: use anchor mark instead of sel tag
Date: Thu, 12 Dec 2013 01:36:40 +0200	[thread overview]
Message-ID: <20131211233640.GA4985@wheezy.local> (raw)
In-Reply-To: <1ld8zlh.1h4guajnkaralM%lists@haller-berlin.de>

---

I hacked somehow around this. It seems that just usilg the
anchor mark should be enough to implement almost the same
behavior. The hard part is that I don't know which feature
is intentional and which is just random consequence of using
sel for search highlight.

One thing which seems to me important and not possible to
implement without using another mask or tag is to return
currentsearchhit back when user removes characters from the
end of search string, and it starts to match previous
places.

This is not intended as patch for merging, just proof of
concept.

 gitk-git/gitk | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index cf25472..c8b223f 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -8320,24 +8320,29 @@ proc settabs {{firstab {}}} {
 proc incrsearch {name ix op} {
     global ctext searchstring searchdirn
 
-    if {[catch {$ctext index anchor}]} {
+    if {[catch {set prev_anchor [$ctext index anchor]}]} {
 	# no anchor set, use start of selection, or of visible area
 	set sel [$ctext tag ranges sel]
 	if {$sel ne {}} {
-	    $ctext mark set anchor [lindex $sel 0]
+	    set start [lindex $sel 0]
 	} elseif {$searchdirn eq "-forwards"} {
-	    $ctext mark set anchor @0,0
+	    set start @0,0
+	} else {
+	    set start @0,[winfo height $ctext]
+	}
+    } else {
+	if {$searchdirn eq "-forwards"} {
+	    set start $prev_anchor
 	} else {
-	    $ctext mark set anchor @0,[winfo height $ctext]
+	    set start "$prev_anchor + [string length $searchstring] c"
 	}
     }
     if {$searchstring ne {}} {
-	set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
+	set here [$ctext search -count mlen $searchdirn -- $searchstring $start]
 	if {$here ne {}} {
 	    $ctext see $here
 	    set mend "$here + $mlen c"
-	    $ctext tag remove sel 1.0 end
-	    $ctext tag add sel $here $mend
+	    $ctext mark set anchor $here
 	    suppress_highlighting_file_for_current_scrollpos
 	    highlightfile_for_scrollpos $here
 	}
@@ -8355,7 +8360,7 @@ proc dosearch {} {
 	set sel [$ctext tag ranges sel]
 	if {$sel ne {}} {
 	    set start "[lindex $sel 0] + 1c"
-	} elseif {[catch {set start [$ctext index anchor]}]} {
+	} elseif {[catch {set start "[$ctext index anchor] + 1c"}]} {
 	    set start "@0,0"
 	}
 	set match [$ctext search -count mlen -- $searchstring $start]
@@ -8368,8 +8373,7 @@ proc dosearch {} {
 	suppress_highlighting_file_for_current_scrollpos
 	highlightfile_for_scrollpos $match
 	set mend "$match + $mlen c"
-	$ctext tag add sel $match $mend
-	$ctext mark unset anchor
+	$ctext mark set anchor $match
 	rehighlight_search_results
     }
 }
@@ -8397,8 +8401,7 @@ proc dosearchback {} {
 	suppress_highlighting_file_for_current_scrollpos
 	highlightfile_for_scrollpos $match
 	set mend "$match + $ml c"
-	$ctext tag add sel $match $mend
-	$ctext mark unset anchor
+        $ctext mark set anchor $match
 	rehighlight_search_results
     }
 }
@@ -8418,14 +8421,15 @@ proc searchmark {first last} {
     global ctext searchstring
     puts [list $first $last]
 
-    set sel [$ctext tag ranges sel]
+    #TODO: catch no anchor
+    set anchor [$ctext index anchor]
 
     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"
-	if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
+	if {$anchor eq $match} {
 	    $ctext tag add currentsearchhit $match $mend
 	} else {
 	    $ctext tag add found $match $mend
-- 
1.8.4.2.1566.g3c1a064

      parent reply	other threads:[~2013-12-11 23:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 18:06 [PATCH] gitk: make pointer selection visible in highlighted lines Max Kirillov
2013-11-27 19:16 ` Thomas Rast
2013-11-27 20:29 ` Eric Sunshine
2013-11-28 21:20 ` [PATCH v2] " Max Kirillov
2013-12-01 22:41   ` Paul Mackerras
2013-12-02 10:04     ` Stefan Haller
2013-12-03  0:35       ` Max Kirillov
2013-12-11 23:36       ` Max Kirillov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131211233640.GA4985@wheezy.local \
    --to=max@max630.net \
    --cc=git@vger.kernel.org \
    --cc=lists@haller-berlin.de \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).