@matheusbsbs / matheus-bagliano / commits / 8a965b8ee2
Fork 0

git-gui: Move on to the next filename after staging/unstaging a change

Suppose the "Unstaged Changes" pane contains a list of files, and one of them is selected (i.e., that diff is currently being displayed). If one clicks on the icon to stage the change, git-gui clears the diff and one has to click on another filename to see the next diff in the list. This patch changes that behaviour. If one clicks on the icon to stage (or unstage) the file whose diff is being displayed, git-gui will move on to the next filename in the list and display that diff instead of a blank diff pane. If the selected file was at the end of the list, the diff pane will display the previous diff instead; if the selected file was the only one listed, the diff pane will become blank. If no diff is currently being displayed, this patch changes nothing. Signed-off-by: Abhijit Menon-Sen <ams@toroid.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Abhijit Menon-Sen committed Jun 13, 2008 at 03:42 UTC 8a965b8ee28bedc58641453e13d03f80180320dd
1 file changed +27 -2
git-gui.sh
+27 -2
@@ -1774,6 +1774,11 @@ proc do_commit {} {
1774 commit_tree
1775 }
1776
1777 +proc next_diff {} {
1778 + global next_diff_p next_diff_w next_diff_i
1779 + show_diff $next_diff_p $next_diff_w $next_diff_i
1780 +}
1781 +
1782 proc toggle_or_diff {w x y} {
1783 global file_states file_lists current_diff_path ui_index ui_workdir
1784 global last_clicked selected_paths
@@ -1793,11 +1798,31 @@ proc toggle_or_diff {w x y} {
1798 $ui_workdir tag remove in_sel 0.0 end
1799
1800 if {$col == 0} {
1796 - if {$current_diff_path eq $path} {
1801 + set i [expr {$lno-1}]
1802 + set ll [expr {[llength $file_lists($w)]-1}]
1803 +
1804 + if {$i == $ll && $i == 0} {
1805 set after {reshow_diff;}
1806 } else {
1799 - set after {}
1807 + global next_diff_p next_diff_w next_diff_i
1808 +
1809 + if {$i < $ll} {
1810 + set i [expr {$i + 1}]
1811 + } else {
1812 + set i [expr {$i - 1}]
1813 + }
1814 +
1815 + set next_diff_i $i
1816 + set next_diff_w $w
1817 + set next_diff_p [lindex $file_lists($w) $i]
1818 +
1819 + if {$next_diff_p ne {} && $current_diff_path ne {}} {
1820 + set after {next_diff;}
1821 + } else {
1822 + set after {}
1823 + }
1824 }
1825 +
1826 if {$w eq $ui_index} {
1827 update_indexinfo \
1828 "Unstaging [short_path $path] from commit" \