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