Prior to this change the since_buffer failed to include input
characters when the state handler returned non-zero.

With this change the current character is already in the
since_buffer when the state handler is invoked so it doesn't
matter if the handler suppresses a state transition.
---
 input.c |   26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/input.c b/input.c
index 34b1de6..b95101c 100644
--- a/input.c
+++ b/input.c
@@ -51,6 +51,7 @@ struct input_transition;
 int    input_split(struct input_ctx *);
 int    input_get(struct input_ctx *, u_int, int, int);
 void   input_reply(struct input_ctx *, const char *, ...);
+void   update_since_ground_buffer(struct input_ctx *);
 void   input_set_state(struct input_ctx *, const struct input_state *);
 
 /* Transition entry/exit handlers. */
@@ -706,11 +707,19 @@ input_free(struct window_pane *wp)
                evbuffer_free(wp->ictx.since_ground);
 }
 
+void
+update_since_ground_buffer(struct input_ctx *ictx)
+{
+       struct evbuffer *ground_evb = ictx->since_ground;
+       if (ictx->state == &input_state_ground)
+               evbuffer_drain(ground_evb, EVBUFFER_LENGTH(ground_evb));
+       evbuffer_add(ictx->since_ground, &ictx->ch, 1);
+}
+
 /* Change input state. */
 void
 input_set_state(struct input_ctx *ictx, const struct input_state *next_state)
 {
-       struct evbuffer         *ground_evb = ictx->since_ground;
 
        if (next_state == NULL)
                return;
@@ -718,9 +727,6 @@ input_set_state(struct input_ctx *ictx, const struct 
input_state *next_state)
        if (ictx->state->exit != NULL)
                ictx->state->exit(ictx);
 
-       if (next_state == &input_state_ground)
-               evbuffer_drain(ground_evb, EVBUFFER_LENGTH(ground_evb));
-
        ictx->state = next_state;
        if (ictx->state->enter != NULL)
                ictx->state->enter(ictx);
@@ -773,18 +779,14 @@ input_parse(struct window_pane *wp)
                        fatalx("No transition from state!");
                }
 
+               update_since_ground_buffer(ictx);
+
                /*
                 * Execute the handler, if any. Don't switch state if it
                 * returns non-zero.
                 */
-               if (itr->handler != NULL && itr->handler(ictx) != 0)
-                       continue;
-
-               input_set_state(ictx, itr->state);
-
-               /* If not in ground state, save input. */
-               if (ictx->state != &input_state_ground)
-                       evbuffer_add(ictx->since_ground, &ictx->ch, 1);
+               if (itr->handler == NULL || itr->handler(ictx) == 0)
+                       input_set_state(ictx, itr->state);
        }
 
        /* Close the screen. */
-- 
1.7.10.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to