threads / patch / 12902

patchgit-gui: Add shortcut keys for Show More/Less Context

Subject: [PATCH] git-gui: Add shortcut keys for Show More/Less Context

## tl;dr

2 messages between Mar 28, 2008 and Mar 29, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Jonathan del Strother· Mar 28, 2008, 13:22 UTC · lore

Bound to Ctrl/Cmd (depending on your platform) + left & right square brackets. ---

I'm not at all familiar with Tcl, so I apologise in advance for any wrongness. I frequently find myself repeatedly right-clicking->Show Less Context in order to stage a specific hunk, seems like a shortcut for this would be useful. Thoughts?

 git-gui/git-gui.sh |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
Show changes to git-gui/git-gui.sh +18 −8
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 5e97fbf..c476753 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -1845,7 +1845,21 @@ proc add_range_to_selection {w x y} {
 	}
 	$w tag add in_sel $begin.0 [expr {$end + 1}].0
 }
+proc show_more_context {} {
+	global repo_config
+	if {$repo_config(gui.diffcontext) < 99} {
+		incr repo_config(gui.diffcontext)
+		reshow_diff
+	}
+}

+proc show_less_context {} {
+	global repo_config
+	if {$repo_config(gui.diffcontext) >= 1} {
+		incr repo_config(gui.diffcontext) -1
+		reshow_diff
+	}
+}
 ######################################################################
 ##
 ## ui construction
@@ -2593,17 +2607,11 @@ lappend diff_actions [list $ctxm entryconf
$ui_diff_applyhunk -state]
 $ctxm add separator
 $ctxm add command \
 	-label [mc "Show Less Context"] \
-	-command {if {$repo_config(gui.diffcontext) >= 1} {
-		incr repo_config(gui.diffcontext) -1
-		reshow_diff
-	}}
+	-command show_less_context
 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
 $ctxm add command \
 	-label [mc "Show More Context"] \
-	-command {if {$repo_config(gui.diffcontext) < 99} {
-		incr repo_config(gui.diffcontext)
-		reshow_diff
-	}}
+	-command show_more_context
 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
 $ctxm add separator
 $ctxm add command \
@@ -2695,6 +2703,8 @@ bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W
see insert; break}
 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
+bind $ui_comm <$M1B-Key-\[> {show_less_context;break}
+bind $ui_comm <$M1B-Key-\]> {show_more_context;break}

 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
-- 
1.5.4.3.450.gb92176.dirty
Shawn O. Pearce· Mar 29, 2008, 05:44 UTC · re: Jonathan del Strother · lore

Re: [PATCH] git-gui: Add shortcut keys for Show More/Less Context

Jonathan del Strother <maillist@steelskies.com> wrote:
Show 7 quoted lines
> Bound to Ctrl/Cmd (depending on your platform) + left & right square brackets.
> ---
> 
> I'm not at all familiar with Tcl, so I apologise in advance for any
> wrongness.  I frequently find myself repeatedly right-clicking->Show
> Less Context in order to stage a specific hunk, seems like a shortcut
> for this would be useful.  Thoughts?

Looks good to me. FWIW your patch was sent with a content-type of format=flawed, so I had to manually unwrap the diff hunk headers to get it to apply.

I think we should also put these into the menu bar too, like say the commit menu, so users can see what the keyboard action is to invoke the increase/decrease.

Also, missing a Signed-off-by line.  If you can contribute
this change according to the statement outlined in
Documentation/SubmittingPatches please send me one.
 
-- 
Shawn.

← back to recent threads