From 2c0f826c360fc5a8f0e125759b596eb28441ba65 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 08:56:24 +0000 Subject: Mouse bindings and hooks set up an initial current state when running a command. This is used for the session, window and pane for all commands in the command sequence if there is no -t or -s. However, using it for all commands in the command sequence means that if the active pane or current session is changed, subsequent commands still use the previous state. So make commands which explicitly change the current state (such as neww and selectp) update it themselves for later commands. Commands which may invalidate the state (like killp) are already OK because an invalid state will be ignored. Also fill in the current state for all key bindings rather than just the mouse, so that any omissions are easier to spot. --- cmd-select-window.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'cmd-select-window.c') diff --git a/cmd-select-window.c b/cmd-select-window.c index b741af51..4cc4b536 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -84,9 +84,10 @@ const struct cmd_entry cmd_last_window_entry = { static enum cmd_retval cmd_select_window_exec(struct cmd *self, struct cmdq_item *item) { - struct winlink *wl = item->state.tflag.wl; - struct session *s = item->state.tflag.s; - int next, previous, last, activity; + struct cmd_find_state *current = &item->shared->current; + struct winlink *wl = item->state.tflag.wl; + struct session *s = item->state.tflag.s; + int next, previous, last, activity; next = self->entry == &cmd_next_window_entry; if (args_has(self->args, 'n')) @@ -116,7 +117,7 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } } - + cmd_find_from_session(&item->shared->current, s); server_redraw_session(s); } else { /* @@ -128,9 +129,13 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "no last window"); return (-1); } + if (current->s == s) + cmd_find_from_session(current, s); server_redraw_session(s); - } else if (session_select(s, wl->idx) == 0) + } else if (session_select(s, wl->idx) == 0) { + cmd_find_from_session(current, s); server_redraw_session(s); + } } recalculate_sizes(); -- cgit From ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 10:22:39 +0000 Subject: Get rid of the extra layer of flags and cmd_prepare() and just store the CMD_FIND_* flags in the cmd_entry and call it for the command. Commands with special requirements call it themselves and update the target for hooks to use. --- cmd-select-window.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cmd-select-window.c') diff --git a/cmd-select-window.c b/cmd-select-window.c index 4cc4b536..6cfaf535 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -36,7 +36,7 @@ const struct cmd_entry cmd_select_window_entry = { .args = { "lnpTt:", 0, 0 }, .usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE, - .tflag = CMD_WINDOW, + .target = { 't', CMD_FIND_WINDOW, 0 }, .flags = 0, .exec = cmd_select_window_exec @@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_window_entry = { .args = { "at:", 0, 0 }, .usage = "[-a] " CMD_TARGET_SESSION_USAGE, - .tflag = CMD_SESSION, + .target = { 't', CMD_FIND_SESSION, 0 }, .flags = 0, .exec = cmd_select_window_exec @@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_window_entry = { .args = { "at:", 0, 0 }, .usage = "[-a] " CMD_TARGET_SESSION_USAGE, - .tflag = CMD_SESSION, + .target = { 't', CMD_FIND_SESSION, 0 }, .flags = 0, .exec = cmd_select_window_exec @@ -75,7 +75,7 @@ const struct cmd_entry cmd_last_window_entry = { .args = { "t:", 0, 0 }, .usage = CMD_TARGET_SESSION_USAGE, - .tflag = CMD_SESSION, + .target = { 't', CMD_FIND_SESSION, 0 }, .flags = 0, .exec = cmd_select_window_exec @@ -85,8 +85,8 @@ static enum cmd_retval cmd_select_window_exec(struct cmd *self, struct cmdq_item *item) { struct cmd_find_state *current = &item->shared->current; - struct winlink *wl = item->state.tflag.wl; - struct session *s = item->state.tflag.s; + struct winlink *wl = item->target.wl; + struct session *s = item->target.s; int next, previous, last, activity; next = self->entry == &cmd_next_window_entry; -- cgit