kill-window -a cannot just walk the list of windows because if

renumber-windows is on, the window it wants to keep could be moved.
Change to renumber afterwards and also behave better if the window is
linked into the session twice. GitHub issue 2287.
This commit is contained in:
nicm
2020-07-04 14:24:02 +00:00
parent 43e1577b5d
commit 1e42689661
5 changed files with 75 additions and 31 deletions

View File

@ -183,7 +183,7 @@ server_kill_pane(struct window_pane *wp)
struct window *w = wp->window;
if (window_count_panes(w) == 1) {
server_kill_window(w);
server_kill_window(w, 1);
recalculate_sizes();
} else {
server_unzoom_window(w);
@ -195,19 +195,15 @@ server_kill_pane(struct window_pane *wp)
}
void
server_kill_window(struct window *w)
server_kill_window(struct window *w, int renumber)
{
struct session *s, *next_s, *target_s;
struct session_group *sg;
struct winlink *wl;
next_s = RB_MIN(sessions, &sessions);
while (next_s != NULL) {
s = next_s;
next_s = RB_NEXT(sessions, &sessions, s);
struct session *s, *s1;
struct winlink *wl;
RB_FOREACH_SAFE(s, sessions, &sessions, s1) {
if (!session_has(s, w))
continue;
server_unzoom_window(w);
while ((wl = winlink_find_by_window(&s->windows, w)) != NULL) {
if (session_detach(s, wl)) {
@ -217,17 +213,35 @@ server_kill_window(struct window *w)
server_redraw_session_group(s);
}
if (options_get_number(s->options, "renumber-windows")) {
if ((sg = session_group_contains(s)) != NULL) {
TAILQ_FOREACH(target_s, &sg->sessions, gentry)
session_renumber_windows(target_s);
} else
session_renumber_windows(s);
}
if (renumber)
server_renumber_session(s);
}
recalculate_sizes();
}
void
server_renumber_session(struct session *s)
{
struct session_group *sg;
if (options_get_number(s->options, "renumber-windows")) {
if ((sg = session_group_contains(s)) != NULL) {
TAILQ_FOREACH(s, &sg->sessions, gentry)
session_renumber_windows(s);
} else
session_renumber_windows(s);
}
}
void
server_renumber_all(void)
{
struct session *s;
RB_FOREACH(s, sessions, &sessions)
server_renumber_session(s);
}
int
server_link_window(struct session *src, struct winlink *srcwl,
struct session *dst, int dstidx, int killflag, int selectflag,
@ -354,7 +368,7 @@ server_destroy_pane(struct window_pane *wp, int notify)
window_remove_pane(w, wp);
if (TAILQ_EMPTY(&w->panes))
server_kill_window(w);
server_kill_window(w, 1);
else
server_redraw_window(w);
}