keyboard-select: e/E mappings

This commit is contained in:
Bert 2010-11-29 19:29:17 +01:00
parent fd641d94d2
commit b77e306229

View File

@ -1,7 +1,7 @@
#! perl -w #! perl -w
# Author: Bert Muennich # Author: Bert Muennich
# Website: http://www.github.com/muennich/urxvt-perls # Website: http://www.github.com/muennich/urxvt-perls
# Version: 1.4 # Version: git-20101129
# License: GPLv2 # License: GPLv2
# Use keyboard shortcuts to select and copy text. # Use keyboard shortcuts to select and copy text.
@ -15,7 +15,7 @@
# Use Meta-Escape to activate selection mode, then use the following keys: # Use Meta-Escape to activate selection mode, then use the following keys:
# h/j/k/l: Move cursor left/down/up/right (also with arrow keys) # h/j/k/l: Move cursor left/down/up/right (also with arrow keys)
# g/G/0/^/$/H/M/L/f/F/;/,/w/W/b/B: More vi-like cursor movement keys # g/G/0/^/$/H/M/L/f/F/;/,/w/W/b/B/e/E: More vi-like cursor movement keys
# '/'/?: Start forward/backward search # '/'/?: Start forward/backward search
# n/N: Repeat last search, N: in reverse direction # n/N: Repeat last search, N: in reverse direction
# Ctrl-f/b: Scroll down/up one screen # Ctrl-f/b: Scroll down/up one screen
@ -34,6 +34,8 @@ sub on_start{
$self->{patterns}{'W'} = qr/\s\S/; $self->{patterns}{'W'} = qr/\s\S/;
$self->{patterns}{'b'} = qr/.*(?:\w[^\w\s]|\W\w|\s\S)/; $self->{patterns}{'b'} = qr/.*(?:\w[^\w\s]|\W\w|\s\S)/;
$self->{patterns}{'B'} = qr/.*\s\S/; $self->{patterns}{'B'} = qr/.*\s\S/;
$self->{patterns}{'e'} = qr/[^\w\s](?=\w)|\w(?=\W)|\S(?=\s|$)/;
$self->{patterns}{'E'} = qr/\S(?=\s|$)/;
() ()
} }
@ -153,7 +155,7 @@ sub key_press {
$self->{move_to} = 1; $self->{move_to} = 1;
$self->{move_dir} = $key eq 'F' ? -1 : 1; $self->{move_dir} = $key eq 'F' ? -1 : 1;
status_area($self, $key); status_area($self, $key);
} elsif (';,wWbB' =~ m/\Q$key\E/) { } elsif (';,wWbBeE' =~ m/\Q$key\E/) {
move_to($self, $key); move_to($self, $key);
} elsif ($key eq '/' || $key eq '?') { } elsif ($key eq '/' || $key eq '?') {
$self->{search} = $key; $self->{search} = $key;
@ -233,6 +235,7 @@ sub move_to {
my ($self, $key) = @_; my ($self, $key) = @_;
my ($cr, $cc) = $self->screen_cur(); my ($cr, $cc) = $self->screen_cur();
my $line = $self->line($cr); my $line = $self->line($cr);
my $offset = $self->{offset};
my ($dir, $pattern); my ($dir, $pattern);
my ($wrap, $found) = (0, 0); my ($wrap, $found) = (0, 0);
@ -241,47 +244,53 @@ sub move_to {
$pattern = $self->{patterns}{sprintf('f%+d', $dir)}; $pattern = $self->{patterns}{sprintf('f%+d', $dir)};
return if not $pattern; return if not $pattern;
} else { } else {
if (lc($key) eq 'w') { if (lc($key) eq 'b') {
$dir = 1;
} else {
$dir = -1; $dir = -1;
} else {
$dir = 1;
++$offset if lc($key) eq 'e';
} }
$pattern = $self->{patterns}{$key}; $pattern = $self->{patterns}{$key};
$wrap = 1; $wrap = 1;
} }
if ($dir > 0) { if ($dir > 0) {
my $text = substr($line->t, $self->{offset}); NEXTDOWN: my $text = substr($line->t, $offset);
if ($text =~ m/$pattern/) { if ($text =~ m/$pattern/) {
$self->{offset} += $+[0] - 1; $offset += $+[0] - 1;
$found = 1; $found = 1;
} elsif ($wrap && $line->end + 1 < $self->nrow) { } elsif ($wrap && $line->end + 1 < $self->nrow) {
$cr = $line->end + 1; $cr = $line->end + 1;
$line = $self->line($cr); $line = $self->line($cr);
$self->{offset} = 0; $offset = 0;
$found = 1; if (lc($key) eq 'e') {
goto NEXTDOWN;
} else {
$found = 1;
}
} }
} elsif ($dir < 0) { } elsif ($dir < 0) {
NEXT: my $text = substr($line->t, 0, $self->{offset}); NEXTUP: my $text = substr($line->t, 0, $offset);
if ($text =~ m/$pattern/) { if ($text =~ m/$pattern/) {
$self->{offset} += $+[0] - length($text) - 1; $offset += $+[0] - length($text) - 1;
$found = 1; $found = 1;
} elsif ($wrap) { } elsif ($wrap) {
if ($self->{offset} > 0) { if ($offset > 0) {
$self->{offset} = 0; $offset = 0;
$found = 1; $found = 1;
} elsif ($line->beg > $self->top_row) { } elsif ($line->beg > $self->top_row) {
$cr = $line->beg - 1; $cr = $line->beg - 1;
$line = $self->line($cr); $line = $self->line($cr);
$self->{offset} = $line->l; $offset = $line->l;
goto NEXT; goto NEXTUP;
} }
} }
} }
if ($found) { if ($found) {
$self->{dollar} = 0; $self->{dollar} = 0;
$self->screen_cur($line->coord_of($self->{offset})); $self->{offset} = $offset;
$self->screen_cur($line->coord_of($offset));
$self->want_refresh(); $self->want_refresh();
} }