From 2e98c9057de6c5700ca01bd58932373b103ef976 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 17 Apr 2014 09:13:13 +0000 Subject: [PATCH] Correct the dance to fix the active pane in join-pane by pulling the (right) code from break-pane and window_remove_pane into a helper function. --- cmd-break-pane.c | 11 +---------- cmd-join-pane.c | 6 +----- tmux.h | 1 + window.c | 8 +++++++- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/cmd-break-pane.c b/cmd-break-pane.c index defd22ec..85c5d4d9 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -65,16 +65,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq) server_unzoom_window(w); TAILQ_REMOVE(&w->panes, wp, entry); - if (wp == w->active) { - w->active = w->last; - w->last = NULL; - if (w->active == NULL) { - w->active = TAILQ_PREV(wp, window_panes, entry); - if (w->active == NULL) - w->active = TAILQ_NEXT(wp, entry); - } - } else if (wp == w->last) - w->last = NULL; + window_lost_pane(w, wp); layout_close_pane(wp); w = wp->window = window_create1(s->sx, s->sy); diff --git a/cmd-join-pane.c b/cmd-join-pane.c index b70f93dc..7d7b1eea 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -139,11 +139,7 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window) layout_close_pane(src_wp); - if (src_w->active == src_wp) { - src_w->active = TAILQ_PREV(src_wp, window_panes, entry); - if (src_w->active == NULL) - src_w->active = TAILQ_NEXT(src_wp, entry); - } + window_lost_pane(src_w, src_wp); TAILQ_REMOVE(&src_w->panes, src_wp, entry); if (window_count_panes(src_w) == 0) diff --git a/tmux.h b/tmux.h index 18cfbbe1..491027fe 100644 --- a/tmux.h +++ b/tmux.h @@ -2138,6 +2138,7 @@ struct window_pane *window_add_pane(struct window *, u_int); void window_resize(struct window *, u_int, u_int); int window_zoom(struct window_pane *); int window_unzoom(struct window *); +void window_lost_pane(struct window *, struct window_pane *); void window_remove_pane(struct window *, struct window_pane *); struct window_pane *window_pane_at_index(struct window *, u_int); struct window_pane *window_pane_next_by_number(struct window *, diff --git a/window.c b/window.c index d934dabb..faea6049 100644 --- a/window.c +++ b/window.c @@ -591,7 +591,7 @@ window_add_pane(struct window *w, u_int hlimit) } void -window_remove_pane(struct window *w, struct window_pane *wp) +window_lost_pane(struct window *w, struct window_pane *wp) { if (wp == w->active) { w->active = w->last; @@ -603,6 +603,12 @@ window_remove_pane(struct window *w, struct window_pane *wp) } } else if (wp == w->last) w->last = NULL; +} + +void +window_remove_pane(struct window *w, struct window_pane *wp) +{ + window_lost_pane(w, wp); TAILQ_REMOVE(&w->panes, wp, entry); window_pane_destroy(wp);