tmux: Use move-window for window dragging
Use move-window for window dragging instead of a loop and swap-window. When using -a or -b (i.e. after or before) the target can be occupied and the windows are reordered automatically.
This commit is contained in:
@@ -80,8 +80,7 @@ bind -r C-p prev
|
||||
bind -r N swap-window -d -t :+1
|
||||
bind -r P swap-window -d -t :-1
|
||||
|
||||
# Reorder windows by dragging on status line. This uses a loop and swap-window
|
||||
# as move-window needs the target index to be free.
|
||||
# Reorder windows by dragging on status line.
|
||||
# NOTE: This breaks the stack and last-used window.
|
||||
bind -n MouseDragEnd1Status {
|
||||
# TODO: Can we somehow get the idx of {mouse} without selecting it?
|
||||
@@ -90,17 +89,14 @@ bind -n MouseDragEnd1Status {
|
||||
set -F @target_idx "#{window_index}"
|
||||
if -F "#{!=:#{@source_idx},#{window_index}}" { select-window -t! }
|
||||
|
||||
# Get the right direction to not mess up the order when wrapping around
|
||||
tmux_move_direction="#{?#{e|<:#{@target_idx},#{@source_idx}},:-1,:+1}"
|
||||
tmux_move_target_idx="#{@target_idx}"
|
||||
# Depending on the direction the window must be placed before or after
|
||||
# the target
|
||||
tmux_move_direction="#{?#{e|<:#{@target_idx},#{@source_idx}},-b,-a}"
|
||||
|
||||
run-shell "\
|
||||
while [ $tmux_move_target_idx -ne $(tmux display -a | grep -Po '(?<=^window_index=)[0-9]*') ]; do \
|
||||
tmux swap-window -d -t $tmux_move_direction; \
|
||||
done"
|
||||
# NOTE: uses run-shell so the flag can be passed through a variable
|
||||
run-shell "tmux move-window -t #{@target_idx} $tmux_move_direction"
|
||||
|
||||
setenv -u tmux_move_direction
|
||||
setenv -u tmux_move_target_idx
|
||||
}
|
||||
|
||||
# TODO: Move to beginning or end like in MouseDragEnd1Status
|
||||
|
||||
Reference in New Issue
Block a user