diff --git a/keyboard-select b/keyboard-select index 6ddcc6f..dc24893 100644 --- a/keyboard-select +++ b/keyboard-select @@ -1,7 +1,7 @@ #! perl -w # Author: Bert Muennich # Website: http://www.github.com/muennich/urxvt-perls -# Version: 1.2 +# Version: git-20100902 # License: GPLv2 # Use keyboard shortcuts to select and copy text. @@ -132,8 +132,7 @@ sub move_cursor { } elsif ($key eq 'j' && $line->end < $self->nrow - 1) { $cr = $line->end + 1; } elsif ($key eq 'h' && $self->{offset} > 0) { - $self->{offset} = $line->l - 1 if $self->{offset} >= $line->l; - --$self->{offset}; + $self->{offset} = $line->offset_of($cr, $cc) - 1; $self->{dollar} = 0; } elsif ($key eq 'l' && $self->{offset} < $line->l - 1) { ++$self->{offset}; @@ -162,8 +161,9 @@ sub move_cursor { $self->{offset} = $ltxt =~ m/^ +/ ? $+[0] : 0; $self->{dollar} = 0; } elsif ($key eq '$') { + my $co = $line->offset_of($cr, $cc); + $self->{dollar} = $co + 1; $self->{offset} = $line->l - 1; - $self->{dollar} = 1; } elsif ($key eq 'H') { $cr = $self->view_start(); } elsif ($key eq 'M') { @@ -173,9 +173,9 @@ sub move_cursor { } $line = $self->line($cr); - $self->{offset} = $line->l - 1 if $self->{dollar} or - $self->{offset} >= $line->l; - ($cr, $cc) = $line->coord_of($self->{offset}); + $cc = $self->{dollar} || $self->{offset} >= $line->l ? $line->l - 1 : + $self->{offset}; + ($cr, $cc) = $line->coord_of($cc); $self->screen_cur($cr, $cc); # scroll the current cursor position into visible area @@ -267,11 +267,14 @@ sub refresh { if ($self->{select} eq 'b') { 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; while ($r <= $er) { my $line = $self->line($r); if ($bc < $line->l) { - $ec = $line->l if $self->{dollar}; + $ec = $line->l if $dollar; $self->{selection} .= substr($line->t, $bc, $ec - $bc); my ($br, $bc) = $line->coord_of($bc); my ($er, $ec) = $line->coord_of($ec <= $line->l ? $ec : $line->l);