Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve window move bindings #30

Closed

Conversation

kaykayehnn
Copy link
Contributor

Currently the window move bindings switch focus from the current window to the one we are swapping with our current window. This makes the bindings somewhat unintuitive.

For example, if I'm in a session with 3 windows and the third one is currently focused:

1:A 2:B 3:C*

I would expect that triggering `prefix + <` (moves current window one position to the left) twice would move window C to the first position:

1:C* 2:A 3:B

Current behaviour

current behaviour

The first time the binding is triggered it swaps windows C and B, but it moves focus from C to B

1:A 2:C 3:B*

The second time it swaps the same windows (B and C), but it focuses window C, which brings us back to the initial position:

1:A 2:B 3:C*

New behaviour

This PR changes the bindings to keep focus on the window being moved, which solves the issue

new behaviour

@kaykayehnn kaykayehnn force-pushed the improve-window-move branch from 8c48cbd to e36770b Compare January 8, 2020 00:46
@kaykayehnn kaykayehnn force-pushed the improve-window-move branch from e36770b to a2895b1 Compare January 8, 2020 01:00
@kaykayehnn
Copy link
Contributor Author

Whoops, seems like there is already a PR for this #28 😅

I took a look at the original issue (tmux/tmux#1879) and the tmux changelog. This inconsistency is one of the breaking changes introduced in v3.0 so I added a condition to apply the appropriate binding based on which version of tmux we're running in:

window_move_bindings() {
# V3.0 changed the way tmux handles focus in swap-window. -d is now
# required to keep focus on the current window.
if [ "$(tmux -V | cut -d' ' -f2)" ">" 3.0 ]; then
tmux bind-key -r "<" swap-window -d -t -1
tmux bind-key -r ">" swap-window -d -t +1
else
tmux bind-key -r "<" swap-window -t -1
tmux bind-key -r ">" swap-window -t +1
fi
}

I verified this works correctly in versions 3.0a and 2.9

Use bc for floating point comparison instead of lexicographic order
Replace \d with [0-9] for better compatibility
@bruno- bruno- closed this in ad0bfb2 Feb 10, 2020
@bruno-
Copy link
Member

bruno- commented Feb 10, 2020

Thank you for this PR.
To keep things simple I decided to drop tmux 2.x behavior and just add new flags to the commands.

belminf pushed a commit to belminf/tmux-pain-control that referenced this pull request May 4, 2020
The behavior for this was changed in tmux 3.0
We're adding a flag to keep tmux 2.x behavior.

Thanks @kaykayehnn

Closes tmux-plugins#30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants