keyboard-select: fixed some cursor movement inconsistencies
This commit is contained in:
parent
cbdbb7927e
commit
ea1ccdc416
@ -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.2
|
# Version: git-20100902
|
||||||
# License: GPLv2
|
# License: GPLv2
|
||||||
|
|
||||||
# Use keyboard shortcuts to select and copy text.
|
# Use keyboard shortcuts to select and copy text.
|
||||||
@ -132,8 +132,7 @@ sub move_cursor {
|
|||||||
} elsif ($key eq 'j' && $line->end < $self->nrow - 1) {
|
} elsif ($key eq 'j' && $line->end < $self->nrow - 1) {
|
||||||
$cr = $line->end + 1;
|
$cr = $line->end + 1;
|
||||||
} elsif ($key eq 'h' && $self->{offset} > 0) {
|
} elsif ($key eq 'h' && $self->{offset} > 0) {
|
||||||
$self->{offset} = $line->l - 1 if $self->{offset} >= $line->l;
|
$self->{offset} = $line->offset_of($cr, $cc) - 1;
|
||||||
--$self->{offset};
|
|
||||||
$self->{dollar} = 0;
|
$self->{dollar} = 0;
|
||||||
} elsif ($key eq 'l' && $self->{offset} < $line->l - 1) {
|
} elsif ($key eq 'l' && $self->{offset} < $line->l - 1) {
|
||||||
++$self->{offset};
|
++$self->{offset};
|
||||||
@ -162,8 +161,9 @@ sub move_cursor {
|
|||||||
$self->{offset} = $ltxt =~ m/^ +/ ? $+[0] : 0;
|
$self->{offset} = $ltxt =~ m/^ +/ ? $+[0] : 0;
|
||||||
$self->{dollar} = 0;
|
$self->{dollar} = 0;
|
||||||
} elsif ($key eq '$') {
|
} elsif ($key eq '$') {
|
||||||
|
my $co = $line->offset_of($cr, $cc);
|
||||||
|
$self->{dollar} = $co + 1;
|
||||||
$self->{offset} = $line->l - 1;
|
$self->{offset} = $line->l - 1;
|
||||||
$self->{dollar} = 1;
|
|
||||||
} elsif ($key eq 'H') {
|
} elsif ($key eq 'H') {
|
||||||
$cr = $self->view_start();
|
$cr = $self->view_start();
|
||||||
} elsif ($key eq 'M') {
|
} elsif ($key eq 'M') {
|
||||||
@ -173,9 +173,9 @@ sub move_cursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$line = $self->line($cr);
|
$line = $self->line($cr);
|
||||||
$self->{offset} = $line->l - 1 if $self->{dollar} or
|
$cc = $self->{dollar} || $self->{offset} >= $line->l ? $line->l - 1 :
|
||||||
$self->{offset} >= $line->l;
|
$self->{offset};
|
||||||
($cr, $cc) = $line->coord_of($self->{offset});
|
($cr, $cc) = $line->coord_of($cc);
|
||||||
$self->screen_cur($cr, $cc);
|
$self->screen_cur($cr, $cc);
|
||||||
|
|
||||||
# scroll the current cursor position into visible area
|
# scroll the current cursor position into visible area
|
||||||
@ -267,11 +267,14 @@ sub refresh {
|
|||||||
|
|
||||||
if ($self->{select} eq 'b') {
|
if ($self->{select} eq 'b') {
|
||||||
delete $self->{selection} if $self->{selection};
|
delete $self->{selection} if $self->{selection};
|
||||||
|
my $co = $self->line($cr)->offset_of($cr, $cc);
|
||||||
|
my $dollar = $self->{dollar} && $co >= $self->{dollar} - 1;
|
||||||
|
|
||||||
my $r = $br;
|
my $r = $br;
|
||||||
while ($r <= $er) {
|
while ($r <= $er) {
|
||||||
my $line = $self->line($r);
|
my $line = $self->line($r);
|
||||||
if ($bc < $line->l) {
|
if ($bc < $line->l) {
|
||||||
$ec = $line->l if $self->{dollar};
|
$ec = $line->l if $dollar;
|
||||||
$self->{selection} .= substr($line->t, $bc, $ec - $bc);
|
$self->{selection} .= substr($line->t, $bc, $ec - $bc);
|
||||||
my ($br, $bc) = $line->coord_of($bc);
|
my ($br, $bc) = $line->coord_of($bc);
|
||||||
my ($er, $ec) = $line->coord_of($ec <= $line->l ? $ec : $line->l);
|
my ($er, $ec) = $line->coord_of($ec <= $line->l ? $ec : $line->l);
|
||||||
|
Loading…
Reference in New Issue
Block a user