keyboard-select: block selection works again
Trailing newline at last line of block/line selection is removed.
This commit is contained in:
parent
bb236fd586
commit
625c0b1d42
108
keyboard-select
108
keyboard-select
@ -42,11 +42,26 @@ sub key_press {
|
|||||||
deactivate($self);
|
deactivate($self);
|
||||||
} elsif ($char eq 'y' || $keysym == 0xff0d) {
|
} elsif ($char eq 'y' || $keysym == 0xff0d) {
|
||||||
if ($self->{select}) {
|
if ($self->{select}) {
|
||||||
|
if ($self->{select} eq 'b') {
|
||||||
|
$self->selection($self->{selection});
|
||||||
|
$self->selection_grab($event->{time});
|
||||||
|
} else {
|
||||||
my ($br, $bc, $er, $ec) = calc_span($self);
|
my ($br, $bc, $er, $ec) = calc_span($self);
|
||||||
|
$ec = $self->line($er)->l if $self->{select} eq 'l';
|
||||||
$self->selection_beg($br, $bc);
|
$self->selection_beg($br, $bc);
|
||||||
$self->selection_end($er, $ec);
|
$self->selection_end($er, $ec);
|
||||||
$self->selection_make($event->{time}, $self->{select} eq 'b');
|
$self->selection_make($event->{time});
|
||||||
deactivate($self) unless $char eq 'y';
|
}
|
||||||
|
if ($char eq 'y') {
|
||||||
|
if ($self->{select} ne 'b') {
|
||||||
|
$self->selection_beg(1, 0);
|
||||||
|
$self->selection_end(1, 0);
|
||||||
|
}
|
||||||
|
$self->{select} = '';
|
||||||
|
$self->want_refresh();
|
||||||
|
} else {
|
||||||
|
deactivate($self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elsif ($char eq 'V') {
|
} elsif ($char eq 'V') {
|
||||||
toggle_select($self, 'l');
|
toggle_select($self, 'l');
|
||||||
@ -73,34 +88,6 @@ sub key_press {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub tt_write {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub refresh {
|
|
||||||
my ($self) = @_;
|
|
||||||
|
|
||||||
if ($self->{select}) {
|
|
||||||
my ($br, $bc, $er, $ec) = calc_span($self);
|
|
||||||
|
|
||||||
if ($self->{select} eq 'b') {
|
|
||||||
# TODO
|
|
||||||
} else {
|
|
||||||
$self->scr_xor_span($br, $bc, $er, $ec, urxvt::RS_RVid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($self->{select} ne 'l') {
|
|
||||||
# make the cursor visible again
|
|
||||||
my ($cr, $cc) = $self->screen_cur();
|
|
||||||
$self->scr_xor_span($cr, $cc, $cr, $cc + 1, urxvt::RS_RVid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub move_cursor {
|
sub move_cursor {
|
||||||
my ($self, $key) = @_;
|
my ($self, $key) = @_;
|
||||||
my ($cr, $cc) = $self->screen_cur();
|
my ($cr, $cc) = $self->screen_cur();
|
||||||
@ -143,8 +130,8 @@ sub move_cursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$line = $self->line($cr);
|
$line = $self->line($cr);
|
||||||
($cr, $cc) = $line->coord_of($self->{offset} >= $line->l ? $line->l - 1 :
|
($cr, $cc) = $line->coord_of($self->{offset} < $line->l ? $self->{offset} :
|
||||||
$self->{offset});
|
$line->l - 1);
|
||||||
$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
|
||||||
@ -162,6 +149,49 @@ sub move_cursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub tt_write {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub refresh {
|
||||||
|
my ($self) = @_;
|
||||||
|
my $reverse_cursor = $self->{select} ne 'l';
|
||||||
|
my ($cr, $cc) = $self->screen_cur();
|
||||||
|
|
||||||
|
if ($self->{select}) {
|
||||||
|
my ($br, $bc, $er, $ec) = calc_span($self);
|
||||||
|
|
||||||
|
if ($self->{select} eq 'b') {
|
||||||
|
delete $self->{selection} if $self->{selection};
|
||||||
|
my $r = $br;
|
||||||
|
while ($r <= $er) {
|
||||||
|
my $line = $self->line($r);
|
||||||
|
if ($bc < $line->l) {
|
||||||
|
$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);
|
||||||
|
$self->scr_xor_span($br, $bc, $er, $ec, urxvt::RS_RVid);
|
||||||
|
} elsif ($r == $cr) {
|
||||||
|
$reverse_cursor = 0;
|
||||||
|
}
|
||||||
|
$self->{selection} .= "\n" if $line->end < $er;
|
||||||
|
$r = $line->end + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$self->scr_xor_span($br, $bc, $er, $ec, urxvt::RS_RVid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reverse_cursor) {
|
||||||
|
# make the cursor visible again
|
||||||
|
$self->scr_xor_span($cr, $cc, $cr, $cc + 1, urxvt::RS_RVid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub activate {
|
sub activate {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
@ -199,6 +229,7 @@ sub deactivate {
|
|||||||
$self->selection_end(1, 0);
|
$self->selection_end(1, 0);
|
||||||
|
|
||||||
delete $self->{overlay} if $self->{overlay};
|
delete $self->{overlay} if $self->{overlay};
|
||||||
|
delete $self->{selection} if $self->{selection};
|
||||||
|
|
||||||
$self->disable("key_press", "refresh_begin", "refresh_end", "tt_write");
|
$self->disable("key_press", "refresh_begin", "refresh_end", "tt_write");
|
||||||
$self->screen_cur($self->{oldcr}, $self->{oldcc});
|
$self->screen_cur($self->{oldcr}, $self->{oldcc});
|
||||||
@ -278,6 +309,14 @@ sub calc_span {
|
|||||||
my ($cr, $cc) = $self->screen_cur();
|
my ($cr, $cc) = $self->screen_cur();
|
||||||
my ($br, $bc, $er, $ec);
|
my ($br, $bc, $er, $ec);
|
||||||
|
|
||||||
|
if ($self->{select} eq 'b') {
|
||||||
|
$br = $self->line($cr)->beg;
|
||||||
|
$bc = $self->line($cr)->offset_of($cr, $cc);
|
||||||
|
$er = $self->line($self->{ar})->beg;
|
||||||
|
$ec = $self->line($self->{ar})->offset_of($self->{ar}, $self->{ac});
|
||||||
|
($br, $er) = ($er, $br) if $br > $er;
|
||||||
|
($bc, $ec) = ($ec, $bc) if $bc > $ec;
|
||||||
|
} else {
|
||||||
if ($cr < $self->{ar}) {
|
if ($cr < $self->{ar}) {
|
||||||
($br, $bc, $er, $ec) = ($cr, $cc, $self->{ar}, $self->{ac});
|
($br, $bc, $er, $ec) = ($cr, $cc, $self->{ar}, $self->{ac});
|
||||||
} elsif ($cr > $self->{ar}) {
|
} elsif ($cr > $self->{ar}) {
|
||||||
@ -286,15 +325,12 @@ sub calc_span {
|
|||||||
($br, $er) = ($cr, $cr);
|
($br, $er) = ($cr, $cr);
|
||||||
($bc, $ec) = $cc < $self->{ac} ? ($cc, $self->{ac}) : ($self->{ac}, $cc);
|
($bc, $ec) = $cc < $self->{ac} ? ($cc, $self->{ac}) : ($self->{ac}, $cc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($self->{select} eq 'l') {
|
if ($self->{select} eq 'l') {
|
||||||
($br, $er) = ($self->line($br)->beg, $self->line($er)->end);
|
($br, $er) = ($self->line($br)->beg, $self->line($er)->end);
|
||||||
($bc, $ec) = (0, $self->ncol);
|
($bc, $ec) = (0, $self->ncol);
|
||||||
} else {
|
} else {
|
||||||
if ($self->{select} eq 'b') {
|
|
||||||
($br, $er) = ($er, $br) if $br > $er;
|
|
||||||
($bc, $ec) = ($ec, $bc) if $bc > $ec;
|
|
||||||
}
|
|
||||||
++$ec;
|
++$ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user