From: Simon Ruderich Date: Mon, 1 Feb 2016 08:28:17 +0000 (+0100) Subject: add Y (mapping_yank_now) and P (mapping_paste_now) mappings X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=d77e458b9be8e3cfbcbc3b59d2a5a00b8f9eb1d9;p=fcscs%2Ffcscs.git add Y (mapping_yank_now) and P (mapping_paste_now) mappings --- diff --git a/bin/fcscs b/bin/fcscs index 6e3d9cb..bdebda5 100755 --- a/bin/fcscs +++ b/bin/fcscs @@ -558,9 +558,6 @@ sub select_match { $number = int($number / 10); } elsif ($char eq "\n" or $char eq $config->{setting}{alternative_return}) { - if ($number == 0) { # number without selection matches last entry - $number = 1; - } last; # Selecting a new mode requires falling through into the main input @@ -570,7 +567,8 @@ sub select_match { return { key => $char }; # All other mappings stay in the current mode. } elsif (defined (my $m = $config->{mapping}{simple}{$char})) { - $m->($char, $screen, $config, $input); + my $result = $m->($char, $screen, $config, $input); + last if defined $result->{select_match}; next; } else { @@ -585,6 +583,10 @@ sub select_match { $screen->draw_matches($config, $matches, \@remaining); $screen->refresh; } + # Number without selection matches last entry. + if ($number == 0) { + $number = 1; + } $screen->draw_matches($config, $matches, []); # remove matches @@ -692,6 +694,18 @@ sub mapping_paste { return {}; } +sub mapping_paste_now { + my ($key, $screen, $config, $input) = @_; + + $screen->debug('mapping_paste_now', 'started'); + + $config->{state}{handler} = $config->{handler}{paste}; + + return { + select_match => 1, + }; +} + sub mapping_yank { my ($key, $screen, $config, $input) = @_; @@ -705,6 +719,17 @@ sub mapping_yank { return {}; } +sub mapping_yank_now { + my ($key, $screen, $config, $input) = @_; + + $screen->debug('mapping_yank_now', 'started'); + + $config->{state}{handler} = $config->{handler}{yank}; + + return { + select_match => 1, + }; +} =head2 NORMAL MODES @@ -1065,8 +1090,12 @@ The following simple mappings are available by default: =item B

enable pasting (C<\&mapping_paste>) +=item B

paste current selection (like C<\n> but paste) (C<\&mapping_paste_now>) + =item B enable yanking (copying) (C<\&mapping_yank>) +=item B yank current selection (like C<\n> but yank) (C<\&mapping_yank_now>) + =back Note that yanking only uses the GNU screen or Tmux paste buffer by default. To @@ -1107,7 +1136,9 @@ my %mapping_mode = ( ); my %mapping_simple = ( p => \&mapping_paste, + P => \&mapping_paste_now, y => \&mapping_yank, + Y => \&mapping_yank_now, ); =head2 ATTRIBUTES @@ -1291,7 +1322,9 @@ Create a new Curses attribute with the given fore- and background color. mapping_mode_search() mapping_paste() + mapping_paste_now() mapping_yank() + mapping_yank_now() mapping_quit() Used as mappings, see L above. @@ -1368,7 +1401,9 @@ package Fcscs { sub mapping_mode_search { return main::mapping_mode_search(@_); } sub mapping_paste { return main::mapping_paste(@_); } + sub mapping_paste_now { return main::mapping_paste_now(@_); } sub mapping_yank { return main::mapping_yank(@_); } + sub mapping_yank_now { return main::mapping_yank_now(@_); } sub mapping_quit { return main::mapping_quit(@_); } sub handler_yank { return main::handler_yank(@_); }