@matheusbsbs / matheus-bagliano / commits / 25b8fb1e49
Fork 0

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 <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Alexander Gavrilov committed Jul 27, 2008 at 10:35 UTC 25b8fb1e499d0e198e491d10c7023a5f5589e837
1 file changed +14 -4
lib/diff.tcl
+14 -4
@@ -19,6 +19,7 @@ proc clear_diff {} {
19 proc reshow_diff {} {
20 global file_states file_lists
21 global current_diff_path current_diff_side
22 + global ui_diff
23
24 set p $current_diff_path
25 if {$p eq {}} {
@@ -28,7 +29,8 @@ proc reshow_diff {} {
29 || [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} {
30 clear_diff
31 } 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
34 }
35 }
36
@@ -52,7 +54,7 @@ A rescan will be automatically started to find other files which may have the sa
54 rescan ui_ready 0
55 }
56
55 -proc show_diff {path w {lno {}}} {
57 +proc show_diff {path w {lno {}} {scroll_pos {}}} {
58 global file_states file_lists
59 global is_3way_diff diff_active repo_config
60 global ui_diff ui_index ui_workdir
@@ -151,6 +153,10 @@ proc show_diff {path w {lno {}}} {
153 $ui_diff conf -state disabled
154 set diff_active 0
155 unlock_index
156 + if {$scroll_pos ne {}} {
157 + update
158 + $ui_diff yview moveto $scroll_pos
159 + }
160 ui_ready
161 return
162 }
@@ -190,10 +196,10 @@ proc show_diff {path w {lno {}}} {
196 -blocking 0 \
197 -encoding binary \
198 -translation binary
193 - fileevent $fd readable [list read_diff $fd]
199 + fileevent $fd readable [list read_diff $fd $scroll_pos]
200 }
201
196 -proc read_diff {fd} {
202 +proc read_diff {fd scroll_pos} {
203 global ui_diff diff_active
204 global is_3way_diff current_diff_header
205
@@ -282,6 +288,10 @@ proc read_diff {fd} {
288 close $fd
289 set diff_active 0
290 unlock_index
291 + if {$scroll_pos ne {}} {
292 + update
293 + $ui_diff yview moveto $scroll_pos
294 + }
295 ui_ready
296
297 if {[$ui_diff index end] eq {2.0}} {