git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitk: Synchronize highlighting in file view when scrolling diff

From
Stefan Haller <stefan@haller-berlin.de>
Date
Sep 18, 2012, 05:57 UTC
Message-ID
<1347947874-38597-1-git-send-email-stefan@haller-berlin.de>

Whenever the diff pane scrolls, highlight the corresponding file in the file list on the right. For a large commit with many files and long per-file diffs, this makes it easier to keep track of what you're looking at.

This allows simplifying the prevfile and nextfile functions, because all they have to do is scroll the diff pane.

Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
---
 gitk | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/gitk b/gitk
index d93bd99..9e3ec71 100755
--- a/gitk
+++ b/gitk
@@ -7947,10 +7947,9 @@ proc changediffdisp {} {
     $ctext tag conf dresult -elide [lindex $diffelide 1]
 }
 
-proc highlightfile {loc cline} {
-    global ctext cflist cflist_top
+proc highlightfile {cline} {
+    global cflist cflist_top
 
-    $ctext yview $loc
     $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
     $cflist tag add highlight $cline.0 "$cline.0 lineend"
     $cflist see $cline.0
@@ -7962,17 +7961,15 @@ proc prevfile {} {
 
     if {$cmitmode eq "tree"} return
     set prev 0.0
-    set prevline 1
     set here [$ctext index @0,0]
     foreach loc $difffilestart {
 	if {[$ctext compare $loc >= $here]} {
-	    highlightfile $prev $prevline
+	    $ctext yview $prev
 	    return
 	}
 	set prev $loc
-	incr prevline
     }
-    highlightfile $prev $prevline
+    $ctext yview $prev
 }
 
 proc nextfile {} {
@@ -7980,11 +7977,9 @@ proc nextfile {} {
 
     if {$cmitmode eq "tree"} return
     set here [$ctext index @0,0]
-    set line 1
     foreach loc $difffilestart {
-	incr line
 	if {[$ctext compare $loc > $here]} {
-	    highlightfile $loc $line
+	    $ctext yview $loc
 	    return
 	}
     }
@@ -8138,7 +8133,17 @@ proc searchmarkvisible {doall} {
 }
 
 proc scrolltext {f0 f1} {
-    global searchstring
+    global searchstring cmitmode
+    global ctext cflist cflist_top difffilestart
+
+    if {$cmitmode ne "tree" && [info exists difffilestart]} {
+	set top [lindex [split [$ctext index @0,0] .] 0]
+	if {$top < [lindex $difffilestart 0]} {
+	    highlightfile 0
+	} else {
+	    highlightfile [expr {[bsearch $difffilestart $top] + 2}]
+	}
+    }
 
     .bleft.bottom.sb set $f0 $f1
     if {$searchstring ne {}} {
-- 
1.7.12.376.g8258bbd
Next: Peter Oberndorfer
Message 1 of 10 in “gitk: Synchronize highlighting in file view when scrolling diff”
  1. gitk: Synchronize highlighting in file view when scrolling diffStefan Haller, Sep 18, 2012
  2. Peter OberndorferSep 18, 2012
  3. gitk: Synchronize highlighting in file view when scrolling diffStefan Haller, Sep 19, 2012
  4. Paul MackerrasSep 18, 2012
  5. Marc BranchaudSep 19, 2012
  6. gitk: Synchronize highlighting in file view when scrolling diffStefan Haller, Sep 19, 2012
  7. Paul MackerrasSep 23, 2012
  8. Stefan HallerSep 24, 2012
  9. gitk: Do not select file list entries during diff loadingPeter Oberndorfer, Oct 26, 2012
  10. Stefan HallerOct 29, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.