Skip to content

Commit 25b8fb1

Browse files
angavrilovspearce
authored andcommitted
git-gui: Preserve scroll position on reshow_diff.
It is especially useful for Stage/Unstage Line, because they invoke full state scan and diff reload, which originally would reset the scroll position to the top of the file. Signed-off-by: Alexander Gavrilov <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 7e09b15 commit 25b8fb1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/diff.tcl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ proc clear_diff {} {
1919
proc reshow_diff {} {
2020
global file_states file_lists
2121
global current_diff_path current_diff_side
22+
global ui_diff
2223

2324
set p $current_diff_path
2425
if {$p eq {}} {
@@ -28,7 +29,8 @@ proc reshow_diff {} {
2829
|| [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} {
2930
clear_diff
3031
} else {
31-
show_diff $p $current_diff_side
32+
set save_pos [lindex [$ui_diff yview] 0]
33+
show_diff $p $current_diff_side {} $save_pos
3234
}
3335
}
3436

@@ -52,7 +54,7 @@ A rescan will be automatically started to find other files which may have the sa
5254
rescan ui_ready 0
5355
}
5456

55-
proc show_diff {path w {lno {}}} {
57+
proc show_diff {path w {lno {}} {scroll_pos {}}} {
5658
global file_states file_lists
5759
global is_3way_diff diff_active repo_config
5860
global ui_diff ui_index ui_workdir
@@ -151,6 +153,10 @@ proc show_diff {path w {lno {}}} {
151153
$ui_diff conf -state disabled
152154
set diff_active 0
153155
unlock_index
156+
if {$scroll_pos ne {}} {
157+
update
158+
$ui_diff yview moveto $scroll_pos
159+
}
154160
ui_ready
155161
return
156162
}
@@ -190,10 +196,10 @@ proc show_diff {path w {lno {}}} {
190196
-blocking 0 \
191197
-encoding binary \
192198
-translation binary
193-
fileevent $fd readable [list read_diff $fd]
199+
fileevent $fd readable [list read_diff $fd $scroll_pos]
194200
}
195201

196-
proc read_diff {fd} {
202+
proc read_diff {fd scroll_pos} {
197203
global ui_diff diff_active
198204
global is_3way_diff current_diff_header
199205

@@ -282,6 +288,10 @@ proc read_diff {fd} {
282288
close $fd
283289
set diff_active 0
284290
unlock_index
291+
if {$scroll_pos ne {}} {
292+
update
293+
$ui_diff yview moveto $scroll_pos
294+
}
285295
ui_ready
286296

287297
if {[$ui_diff index end] eq {2.0}} {

0 commit comments

Comments
 (0)