From 9ebbce09262eb7a8058ba029e393014a5901ad03 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Fri, 27 Mar 2026 18:12:17 +0100 Subject: [PATCH] when destroying multiple tabs with ctrl-w multiple times always switch to the tab on the left and not on the first tab --- src/xinit.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/xinit.c b/src/xinit.c index 71522a8a..442c9255 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1974,11 +1974,27 @@ static void destroy_tab(int *window_count, const char *win_path) prev = 0; if(previous_win_path[0]) { prev = get_tab_or_window_number(previous_win_path); - dbg(1, "%s, prev=%d\n", previous_win_path, prev); + dbg(0, "%s, prev=%d\n", previous_win_path, prev); if(prev == -1) prev = 0; } xctx = save_xctx[prev]; /* restore previous or main (.drw) schematic */ + /* set previous tab so context will switch to that tab after destroying next one */ + if(prev > 0) { + int last_tab = -1; + int prev_last_tab = -1; + for(i = 0; i < MAX_NEW_WINDOWS; ++i) { + if(save_xctx[i] != NULL) { + prev_last_tab = last_tab; + last_tab = i; + } + } + dbg(0, "last_tab=%d\n", prev_last_tab); + if(prev_last_tab >=0) { + my_strncpy(previous_win_path, save_xctx[prev_last_tab]->current_win_path, sizeof(previous_win_path)); + } + } + /* seems unnecessary; previous tab save_pixmap was not deleted */ /* resetwin(1, 0, 0, 0, 0); */ /* create pixmap. resetwin(create_pixmap, clear_pixmap, force, w, h) */