Add S-Up and S-Down to move windows in tree mode. From David Mandelberg

in GitHub issue 4415.
This commit is contained in:
nicm
2025-03-21 13:36:42 +00:00
parent b7d640e764
commit a541be3951
7 changed files with 109 additions and 10 deletions

View File

@ -902,6 +902,58 @@ window_tree_get_key(void *modedata, void *itemdata, u_int line)
return (key);
}
static int
window_tree_swap(void *cur_itemdata, void *other_itemdata)
{
struct window_tree_itemdata *cur = cur_itemdata;
struct window_tree_itemdata *other = other_itemdata;
struct session *cur_session, *other_session;
struct winlink *cur_winlink, *other_winlink;
struct window *cur_window, *other_window;
struct window_pane *cur_pane, *other_pane;
if (cur->type != other->type)
return (0);
if (cur->type != WINDOW_TREE_WINDOW)
return (0);
window_tree_pull_item(cur, &cur_session, &cur_winlink, &cur_pane);
window_tree_pull_item(other, &other_session, &other_winlink,
&other_pane);
if (cur_session != other_session)
return (0);
if (window_tree_sort->field != WINDOW_TREE_BY_INDEX &&
window_tree_cmp_window(&cur_winlink, &other_winlink) != 0) {
/*
* Swapping indexes would not swap positions in the tree, so
* prevent swapping to avoid confusing the user.
*/
return (0);
}
other_window = other_winlink->window;
TAILQ_REMOVE(&other_window->winlinks, other_winlink, wentry);
cur_window = cur_winlink->window;
TAILQ_REMOVE(&cur_window->winlinks, cur_winlink, wentry);
other_winlink->window = cur_window;
TAILQ_INSERT_TAIL(&cur_window->winlinks, other_winlink, wentry);
cur_winlink->window = other_window;
TAILQ_INSERT_TAIL(&other_window->winlinks, cur_winlink, wentry);
if (cur_session->curw == cur_winlink)
session_set_current(cur_session, other_winlink);
else if (cur_session->curw == other_winlink)
session_set_current(cur_session, cur_winlink);
session_group_synchronize_from(cur_session);
server_redraw_session_group(cur_session);
recalculate_sizes();
return (1);
}
static struct screen *
window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs,
struct args *args)
@ -940,7 +992,7 @@ window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs,
data->data = mode_tree_start(wp, args, window_tree_build,
window_tree_draw, window_tree_search, window_tree_menu, NULL,
window_tree_get_key, data, window_tree_menu_items,
window_tree_get_key, window_tree_swap, data, window_tree_menu_items,
window_tree_sort_list, nitems(window_tree_sort_list), &s);
mode_tree_zoom(data->data, args);