]> granicus.if.org Git - neomutt/commitdiff
Fix tag-prefix to not abort on $timeout.
authorKevin McCarthy <kevin@8t8.us>
Thu, 1 Jun 2017 22:17:05 +0000 (15:17 -0700)
committerRichard Russon <rich@flatcap.org>
Wed, 7 Jun 2017 21:53:18 +0000 (22:53 +0100)
If $timeout is set very low, then it can cancel the tag-prefix before
the user has time to press the desired command.

Change the code to set the tag flag, and then recontinue with normal
event processing instead.  Cancel on an abort, but continue with a timeout.

Thanks to Lauri Tirkkonen for reporting the issue.

curs_main.c
menu.c

index fa5c32efeaf80fb45ee6c516861c5786836eed6f..3b6ae0d76793e7f13432909696e24dc86017060c 100644 (file)
@@ -916,7 +916,11 @@ int mutt_index_menu(void)
 
   while (true)
   {
-    tag = 0; /* clear the tag-prefix */
+    /* Clear the tag prefix unless we just started it.  Don't clear
+     * the prefix on a timeout (op==-2), but do clear on an abort (op==-1)
+     */
+    if (tag && op != OP_TAG_PREFIX && op != OP_TAG_PREFIX_COND && op != -2)
+      tag = 0;
 
     /* check if we need to resort the index because just about
      * any 'op' below could do mutt_enter_command(), either here or
@@ -1037,6 +1041,13 @@ int mutt_index_menu(void)
     {
       index_menu_redraw(menu);
 
+      /* give visual indication that the next command is a tag- command */
+      if (tag)
+      {
+        mutt_window_mvaddstr(MuttMessageWindow, 0, 0, "tag-");
+        mutt_window_clrtoeol(MuttMessageWindow);
+      }
+
       if (menu->current < menu->max)
         menu->oldcurrent = menu->current;
       else
@@ -1071,47 +1082,28 @@ int mutt_index_menu(void)
 
       mutt_debug(4, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op);
 
+      /* either user abort or timeout */
       if (op < 0)
       {
         mutt_timeout_hook();
-        continue; /* either user abort or timeout */
+        if (tag)
+          mutt_window_clearline(MuttMessageWindow, 0);
+        continue;
       }
 
       mutt_curs_set(1);
 
       /* special handling for the tag-prefix function */
-      if (op == OP_TAG_PREFIX)
+      if (op == OP_TAG_PREFIX || op == OP_TAG_PREFIX_COND)
       {
-        if (!Context)
-        {
-          mutt_error(_("No mailbox is open."));
-          continue;
-        }
-
-        if (!Context->tagged)
-        {
-          mutt_error(_("No tagged messages."));
-          continue;
-        }
-        tag = 1;
-
-        /* give visual indication that the next command is a tag- command */
-        mutt_window_mvaddstr(MuttMessageWindow, 0, 0, "tag-");
-        mutt_window_clrtoeol(MuttMessageWindow);
-
-        /* get the real command */
-        if ((op = km_dokey(MENU_MAIN)) == OP_TAG_PREFIX)
+        /* A second tag-prefix command aborts */
+        if (tag)
         {
-          /* abort tag sequence */
+          tag = 0;
           mutt_window_clearline(MuttMessageWindow, 0);
           continue;
         }
-      }
-      else if (option(OPTAUTOTAG) && Context && Context->tagged)
-        tag = 1;
 
-      if (op == OP_TAG_PREFIX_COND)
-      {
         if (!Context)
         {
           mutt_error(_("No mailbox is open."));
@@ -1120,24 +1112,22 @@ int mutt_index_menu(void)
 
         if (!Context->tagged)
         {
-          mutt_flush_macro_to_endcond();
-          mutt_message(_("Nothing to do."));
+          if (op == OP_TAG_PREFIX)
+            mutt_error(_("No tagged messages."));
+          else if (op == OP_TAG_PREFIX_COND)
+          {
+            mutt_flush_macro_to_endcond();
+            mutt_message(_("Nothing to do."));
+          }
           continue;
         }
-        tag = 1;
-
-        /* give visual indication that the next command is a tag- command */
-        mutt_window_mvaddstr(MuttMessageWindow, 0, 0, "tag-");
-        mutt_window_clrtoeol(MuttMessageWindow);
 
         /* get the real command */
-        if ((op = km_dokey(MENU_MAIN)) == OP_TAG_PREFIX)
-        {
-          /* abort tag sequence */
-          mutt_window_clearline(MuttMessageWindow, 0);
-          continue;
-        }
+        tag = 1;
+        continue;
       }
+      else if (option(OPTAUTOTAG) && Context && Context->tagged)
+        tag = 1;
 
       mutt_clear_error();
     }
diff --git a/menu.c b/menu.c
index 3f454a568110bde81b8682be691e23d041d5f18a..05f2db28a04c04698e2e1354764cc69999f93a50 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1073,18 +1073,28 @@ int mutt_menu_loop(struct Menu *menu)
       return OP_NULL;
     }
 
+    /* Clear the tag prefix unless we just started it.  Don't clear
+     * the prefix on a timeout (i==-2), but do clear on an abort (i==-1)
+     */
+    if (menu->tagprefix && i != OP_TAG_PREFIX && i != OP_TAG_PREFIX_COND && i != -2)
+      menu->tagprefix = 0;
 
     mutt_curs_set(0);
 
     if (menu_redraw(menu) == OP_REDRAW)
       return OP_REDRAW;
 
+    /* give visual indication that the next command is a tag- command */
+    if (menu->tagprefix)
+    {
+      mutt_window_mvaddstr(menu->messagewin, 0, 0, "tag-");
+      mutt_window_clrtoeol(menu->messagewin);
+    }
+
     menu->oldcurrent = menu->current;
 
 
     /* move the cursor out of the way */
-
-
     if (option(OPTARROWCURSOR))
       mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 2);
     else if (option(OPTBRAILLEFRIENDLY))
@@ -1102,13 +1112,17 @@ int mutt_menu_loop(struct Menu *menu)
     i = km_dokey(menu->menu);
     if (i == OP_TAG_PREFIX || i == OP_TAG_PREFIX_COND)
     {
+      if (menu->tagprefix)
+      {
+        menu->tagprefix = 0;
+        mutt_window_clearline(menu->messagewin, 0);
+        continue;
+      }
+
       if (menu->tagged)
       {
-        mutt_window_mvaddstr(menu->messagewin, 0, 0, "Tag-");
-        mutt_window_clrtoeol(menu->messagewin);
-        i = km_dokey(menu->menu);
         menu->tagprefix = 1;
-        mutt_window_clearline(menu->messagewin, 0);
+        continue;
       }
       else if (i == OP_TAG_PREFIX)
       {
@@ -1124,8 +1138,6 @@ int mutt_menu_loop(struct Menu *menu)
     }
     else if (menu->tagged && option(OPTAUTOTAG))
       menu->tagprefix = 1;
-    else
-      menu->tagprefix = 0;
 
     mutt_curs_set(1);
 
@@ -1139,7 +1151,11 @@ int mutt_menu_loop(struct Menu *menu)
 #endif
 
     if (i < 0)
+    {
+      if (menu->tagprefix)
+        mutt_window_clearline(menu->messagewin, 0);
       continue;
+    }
 
     if (!menu->dialog)
       mutt_clear_error();