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-attach-session.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cmd-attach-session.c') diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 684fc3f1..22d9320d 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -50,6 +50,7 @@ enum cmd_retval cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, const char *cflag, int Eflag) { + struct cmd_find_state *current = &item->shared->current; struct session *s = item->state.tflag.s; struct client *c = item->client, *c_loop; struct winlink *wl = item->state.tflag.wl; @@ -73,6 +74,10 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, if (wp != NULL) window_set_active_pane(wp->window, wp); session_set_current(s, wl); + if (wp != NULL) + cmd_find_from_winlink_pane(current, wl, wp); + else + cmd_find_from_winlink(current, wl); } if (cflag != NULL) { -- 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-attach-session.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'cmd-attach-session.c') diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 22d9320d..81ed4a87 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -40,21 +40,23 @@ const struct cmd_entry cmd_attach_session_entry = { .args = { "c:dErt:", 0, 0 }, .usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE, - .tflag = CMD_SESSION_WITHPANE, + /* -t is special */ .flags = CMD_STARTSERVER, .exec = cmd_attach_session_exec }; enum cmd_retval -cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, - const char *cflag, int Eflag) +cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, + int rflag, const char *cflag, int Eflag) { struct cmd_find_state *current = &item->shared->current; - struct session *s = item->state.tflag.s; + enum cmd_find_type type; + int flags; struct client *c = item->client, *c_loop; - struct winlink *wl = item->state.tflag.wl; - struct window_pane *wp = item->state.tflag.wp; + struct session *s; + struct winlink *wl; + struct window_pane *wp; char *cause; if (RB_EMPTY(&sessions)) { @@ -70,6 +72,19 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, return (CMD_RETURN_ERROR); } + if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') { + type = CMD_FIND_PANE; + flags = 0; + } else { + type = CMD_FIND_SESSION; + flags = CMD_FIND_PREFER_UNATTACHED; + } + if (cmd_find_target(&item->target, item, tflag, type, flags) != 0) + return (CMD_RETURN_ERROR); + s = item->target.s; + wl = item->target.wl; + wp = item->target.wp; + if (wl != NULL) { if (wp != NULL) window_set_active_pane(wp->window, wp); @@ -150,6 +165,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - return (cmd_attach_session(item, args_has(args, 'd'), - args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E'))); + return (cmd_attach_session(item, args_get(args, 't'), + args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'), + args_has(args, 'E'))); } -- cgit