summaryrefslogtreecommitdiffstats
path: root/cmd-find.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-13 10:01:49 +0000
committernicm <nicm>2016-10-13 10:01:49 +0000
commit4d9e6ea3106ea06afa4583254549d525b31ed277 (patch)
tree8532ce29088d6b65b9615271dd6b5fdaa9984ca2 /cmd-find.c
parent05dac2e42c257c87d1fdbc70d0d976f918d77cfd (diff)
Some improvements and bug fixes for hooks:
- Prepare the state again before the "after" hooks are run, because the command may have killed or moved windows. - Use the hooks list from the newly prepared target, not the old hooks list (only matters for new-session really). - Correctly detect an invalid current state and ignore it in cmd_find_target ("killw; swapw"). - Change neww, new, killp, killw, splitw, swapp, swapw to update the current state (used if no explicit target is given) to something more useful after they have finished. For example, neww changes it to the newly created window. Hooks are still relatively new and primitive so there are likely to be more changes to come. Parts based on bug reports from Uwe Werler and Iblis Lin.
Diffstat (limited to 'cmd-find.c')
-rw-r--r--cmd-find.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/cmd-find.c b/cmd-find.c
index dec386ac..10f2fd04 100644
--- a/cmd-find.c
+++ b/cmd-find.c
@@ -803,6 +803,15 @@ cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
fs->idx = -1;
}
+/* Check if state is empty/ */
+int
+cmd_find_empty_state(struct cmd_find_state *fs)
+{
+ if (fs->s == NULL && fs->wl == NULL && fs->w == NULL && fs->wp == NULL)
+ return (1);
+ return (0);
+}
+
/* Check if a state if valid. */
int
cmd_find_valid_state(struct cmd_find_state *fs)
@@ -959,12 +968,19 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
cmd_find_clear_state(fs, cmdq, flags);
/* Find current state. */
- if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED))
+ if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) {
fs->current = &marked_pane;
- else if (cmd_find_valid_state(&cmdq->current))
+ log_debug(" current is marked pane");
+ } else if (cmd_find_valid_state(&cmdq->current)) {
fs->current = &cmdq->current;
- else
+ log_debug(" current is from queue");
+ } else {
fs->current = current;
+ log_debug(" current is from argument");
+ }
+ if (!cmd_find_empty_state(fs->current) &&
+ !cmd_find_valid_state(fs->current))
+ fatalx("invalid current find state");
/* An empty or NULL target is the current. */
if (target == NULL || *target == '\0')