diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c index 7dc6a4358..a97e33da1 100644 --- a/cmd-swap-pane.c +++ b/cmd-swap-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-swap-pane.c,v 1.55 2026/07/15 13:02:33 nicm Exp $ */ +/* $OpenBSD: cmd-swap-pane.c,v 1.56 2026/10/02 12:23:44 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -182,9 +182,15 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) window_set_active_pane(src_w, tmp_wp, 1); } } else { + /* + * Keep the same pane active, unless the swap has covered it + * with a zoomed pane: activating it would hide the zoom. With + * -Z the zoom moves to the active pane afterwards instead. + */ if (src_w->active == src_wp) window_set_active_pane(src_w, dst_wp, 1); - if (dst_w->active == dst_wp) + if (dst_w->active == dst_wp && + (args_has(args, 'Z') || window_pane_is_visible(src_wp))) window_set_active_pane(dst_w, src_wp, 1); } if (src_w != dst_w) { diff --git a/regress/swap-pane.sh b/regress/swap-pane.sh new file mode 100644 index 000000000..8002a6189 --- /dev/null +++ b/regress/swap-pane.sh @@ -0,0 +1,286 @@ +#!/bin/sh + +# swap-pane swaps positions: the layout cell (and so floating or tiled), the +# geometry, and the zoomed and hidden state belong to the position and stay +# behind. Check this within a window and across windows. + +PATH=/bin:/usr/bin +TERM=screen + +[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux) +TMUX="$TEST_TMUX -LtestA$$ -f/dev/null" +trap '$TMUX kill-server 2>/dev/null' 0 +trap 'exit 1' 1 2 15 + +fail() +{ + echo "$*" >&2 + exit 1 +} + +run() +{ + $TMUX "$@" || fail "failed: $*" +} + +# check +check() +{ + got=$(run display-message -p -t "$1" \ + '#{pane_floating_flag}:#{pane_zoomed_flag}:#{pane_hidden_flag}:#{window_index}') || exit 1 + [ "$got" = "$2" ] || fail "$3: $1 got '$got', expected '$2'" +} + +# checkwin