add -p: only display help for active keys
If the user presses a key that add -p wasn't expecting then it prints a list of key bindings. Although the prompt only lists the active bindings the help was printed for all bindings. Fix this by using the list of keys in the prompt to filter the help. Note that the list of keys was already passed to help_patch_cmd() by the caller so there is no change needed to the call site. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Feb 13, 2018 at 10:32 UTC
01a6966021a50dc7aff76c0f951bbdd6e1bdd444
1 file changed
+7
-1
git-add--interactive.perl
+7
-1
@@ -1184,7 +1184,13 @@ d - do not apply this hunk or any of the later hunks in the file"),
1184
);
1185
1186
sub help_patch_cmd {
1187
- print colored $help_color, __($help_patch_modes{$patch_mode}), "\n", __ <<EOF ;
1187
+ local $_;
1188
+ my $other = $_[0] . ",/,?";
1189
+ print colored $help_color, __($help_patch_modes{$patch_mode}), "\n",
1190
+ map { "$_\n" } grep {
1191
+ my $c = quotemeta(substr($_, 0, 1));
1192
+ $other =~ /,$c/
1193
+ } split "\n", __ <<EOF ;
1194
g - select a hunk to go to
1195
/ - search for a hunk matching the given regex
1196
j - leave this hunk undecided, see next undecided hunk