# gitk: synchronize highlighting in file view for 'f'&'b' commands

3 messages from 2008-03-17 to 2008-05-02. Participants: Eric Raible, Paul Mackerras.
Thread: https://gitlist.dev/t/12728

## Eric Raible, 2008-03-17 20:00

Subject: gitk: synchronize highlighting in file view for 'f'&'b' commands
Message-ID: <279b37b20803171300v748b5d23rcc5c0e534429d1be@mail.gmail.com>
URL: https://gitlist.dev/e/279b37b20803171300v748b5d23rcc5c0e534429d1be%40mail.gmail.com

```
Previously, 'b', backspace, and delete all did the same thing.
This changes 'b' to perform the inverse of 'f'.  And both of
them now highlight the filename of the currently diff.

This makes it easier to review and navigate the diffs associated
with a particular commit using only f, b, and space because the
filename of the currently display diff will be dynamically
highlighted.

Signed-off-by: Eric Raible <raible@gmail.com>
---
 gitk-git/gitk |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 84ab02e..51ba3ff 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -1016,7 +1016,7 @@ proc makewindow {} {
     bindkey k "selnextline 1"
     bindkey j "goback"
     bindkey l "goforw"
-    bindkey b "$ctext yview scroll -1 pages"
+    bindkey b prevfile
     bindkey d "$ctext yview scroll 18 units"
     bindkey u "$ctext yview scroll -18 units"
     bindkey / {dofind 1 1}
@@ -5478,18 +5478,34 @@ proc changediffdisp {} {
     $ctext tag conf d1 -elide [lindex $diffelide 1]
 }

+proc highlightfile {loc} {
+    global ctext
+    $ctext yview $loc
+
+    global cmitmode ctext cflist cflist_top
+    if {$cmitmode eq "tree"} return
+
+    $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
+
+    set file [regsub -- "-* (.*?) -*" [$ctext get $loc "$loc lineend"] "\\1"]
+    set cline [$cflist search -regexp [subst {^$file$}] 0.0]
+
+    $cflist tag add highlight $cline "$cline lineend"
+    $cflist see $cline
+    set cflist_top [lindex [split $cline .] 0]
+}
+
 proc prevfile {} {
     global difffilestart ctext
     set prev [lindex $difffilestart 0]
     set here [$ctext index @0,0]
     foreach loc $difffilestart {
        if {[$ctext compare $loc >= $here]} {
-           $ctext yview $prev
+           highlightfile $prev
            return
        }
        set prev $loc
     }
-    $ctext yview $prev
 }

 proc nextfile {} {
@@ -5497,7 +5513,7 @@ proc nextfile {} {
     set here [$ctext index @0,0]
     foreach loc $difffilestart {
        if {[$ctext compare $loc > $here]} {
-           $ctext yview $loc
+           highlightfile $loc
            return
        }
     }
--
1.5.4.2.1161.g1a6f0

```

## Paul Mackerras, 2008-05-02 12:49

Subject: Re: gitk: synchronize highlighting in file view for 'f'&'b' commands
Message-ID: <18459.3557.603906.871664@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18459.3557.603906.871664%40cargo.ozlabs.ibm.com
In-Reply-To: <279b37b20803171300v748b5d23rcc5c0e534429d1be@mail.gmail.com>

```
Eric Raible writes:

> Previously, 'b', backspace, and delete all did the same thing.
> This changes 'b' to perform the inverse of 'f'.  And both of
> them now highlight the filename of the currently diff.

OK, but...

> +    set file [regsub -- "-* (.*?) -*" [$ctext get $loc "$loc lineend"] "\\1"]
> +    set cline [$cflist search -regexp [subst {^$file$}] 0.0]

This seems to be working out the index of the line we want to
highlight in the file list, but both the callers of highlightfile can
supply that info much more easily by incrementing a count as they go
through $difffilestart, as far as I can tell.

Paul.

```

## Eric Raible, 2008-05-02 18:45

Subject: Re: gitk: synchronize highlighting in file view for 'f'&'b' commands
Message-ID: <481B6151.7040707@nextest.com>
URL: https://gitlist.dev/e/481B6151.7040707%40nextest.com
In-Reply-To: <18459.3557.603906.871664@cargo.ozlabs.ibm.com>

```
Paul Mackerras wrote:
> Eric Raible writes:
> 
>> Previously, 'b', backspace, and delete all did the same thing.
>> This changes 'b' to perform the inverse of 'f'.  And both of
>> them now highlight the filename of the currently diff.
> 
> OK, but...
> 
>> +    set file [regsub -- "-* (.*?) -*" [$ctext get $loc "$loc lineend"] "\\1"]
>> +    set cline [$cflist search -regexp [subst {^$file$}] 0.0]
> 
> This seems to be working out the index of the line we want to
> highlight in the file list, but both the callers of highlightfile can
> supply that info much more easily by incrementing a count as they go
> through $difffilestart, as far as I can tell.
> 
> Paul.
> 

That very well might be, but I:

1) wanted to make the smallest possible change
2) didn't peruse the code closely enough to see how to do that

I unfortunately don't have the time to pursue this just now.
Any chance you could take the idea and fly with it?

Thanks - Eric

```
