Skip to content

Commit

Permalink
Introduce :nowrap variants of move_tab_<direction> actions
Browse files Browse the repository at this point in the history
Just like for `next_tab` and `prev_tab`, add a `:nowrap` variant for
`move_tab_left` and `move_tab_right` actions.  When used, moving tabs
stops at the edges of the tab bar rather than moving the tab to
opposite end.  To use the behaviour by default, the Control-Left/Right
keys can be configured to bind to the new actions:

    URxvt.keysym.Control-Left:  tabbedex:move_tab_left:nowrap
    URxvt.keysym.Control-Right: tabbedex:move_tab_right:nowrap

Issue: #42
  • Loading branch information
mina86 committed Oct 12, 2021
1 parent 3d53e10 commit 8e60268
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions tabbedex
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,19 @@ switching right from the last tab or left from the first one.
=item B<tabbedex:next_tab:nowrap> and B<tabbedex:prev_tab:nowrap>
Switches tabs like B<tabbedex:next_tab> and B<tabbedex:prev_tab> action but does
not perform wrapping. I.e. does nothing if trying to switch to the last tab’s
next tab or first tab’s previous tab.
not wrap around. I.e. does nothing if trying to switch to the last tab’s next
tab or first tab’s previous tab.
=item B<tabbedex:move_tab_left> and B<tabbedex:move_tab_right>
Moves the current tab left or right.
Moves the current tab left or right. Wraps around when moving last tab right or
first tab left.
=item B<tabbedex:move_tab_left:nowrap> and B<tabbedex:move_tab_right:nowrap>
Moves the current tab left or right like B<tabbedex:move_tab_left> and
B<tabbedex:move_tab_right> but does not wrap around. I.e. moving first tab left
or last tab right does nothing.
=item B<tabbedex:goto_tab_>I<N>
Expand Down Expand Up @@ -1314,10 +1321,8 @@ sub tab_action {
if (!$2 || ($index >= 0 && $index < @{ $root->{tabs} })) {
$root->make_current($index % @{ $root->{tabs} });
}
} elsif ($cmd eq 'move_tab_left') {
$root->move_tab($tab, -1);
} elsif ($cmd eq 'move_tab_right') {
$root->move_tab($tab, 1);
} elsif ($cmd =~ /^move_tab_(left|right)(:nowrap)?$/) {
$root->move_tab($tab, $1 eq 'left' ? -1 : 1, !!$2);
} elsif ($cmd =~ /^goto_tab[_:](-?)(0*[1-9]\d*)$/) {
if ($2 <= @{ $root->{tabs} }) {
$root->make_current($1 eq '' ? $2 - 1 : -$2);
Expand All @@ -1335,7 +1340,7 @@ sub tab_action {
}

sub move_tab {
my ($root, $tab, $direction) = @_;
my ($root, $tab, $direction, $nowrap) = @_;
if (@{ $root->{tabs} } < 2) {
return;
}
Expand All @@ -1344,15 +1349,18 @@ sub move_tab {
my $idx = $tab->index;

if ($idx == 0 && $direction == -1) {
if ($nowrap) {
return;
}
push @{$root->{tabs}}, shift @{$root->{tabs}};
$idx = $last;
} elsif ($idx == $last && $direction == 1) {
if ($nowrap) {
return;
}
unshift @{$root->{tabs}}, pop @{$root->{tabs}};
$idx = 0;
} else {
($root->{tabs}[$idx], $root->{tabs}[$idx + $direction]) =
($root->{tabs}[$idx + $direction], $root->{tabs}[$idx]);
$idx += $direction;
}
$root->refresh;
}
Expand Down

0 comments on commit 8e60268

Please sign in to comment.