]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - keys.c
Use proper built-in function for getting fraction part
[xonotic/darkplaces.git] / keys.c
diff --git a/keys.c b/keys.c
index 8049bb3b993ad7b637c4143d18fa8e9a69db1ecf..fd0a24b202a07b64491ec1e2dc793db61e774676 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1098,8 +1098,7 @@ static int Key_Convert_NumPadKey(int key)
        return key;
 }
 
-static void
-Key_Console(cmd_state_t *cmd, int key, int unicode)
+static void Key_Console(cmd_state_t *cmd, int key, int unicode)
 {
        int linepos;
 
@@ -1121,8 +1120,9 @@ Key_Console(cmd_state_t *cmd, int key, int unicode)
 
        if ((key == K_ENTER || key == K_KP_ENTER) && KM_NONE)
        {
-               Cbuf_AddText (cmd, key_line+1); // skip the ]
-               Cbuf_AddText (cmd, "\n");
+               // bones_was_here: prepending allows a loop such as `alias foo "bar; wait; foo"; foo`
+               // to be broken with an alias or unalias command
+               Cbuf_InsertText(cmd, key_line+1); // skip the ]
                Key_History_Push();
                key_linepos = Key_ClearEditLine(true);
                // force an update, because the command may take some time
@@ -1971,14 +1971,14 @@ Key_Event (int key, int ascii, qbool down)
                        if(keydown[key] == 1 && down)
                        {
                                // button commands add keynum as a parm
+                               // prepend to avoid delays from `wait` commands added by other sources
                                if (bind[0] == '+')
-                                       Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
+                                       Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
                                else
-                               {
-                                       Cbuf_AddText (cmd, bind);
-                                       Cbuf_AddText (cmd, "\n");
-                               }
-                       } else if(bind[0] == '+' && !down && keydown[key] == 0)
+                                       Cbuf_InsertText(cmd, bind);
+                       }
+                       else if(bind[0] == '+' && !down && keydown[key] == 0)
+                               // append -bind to ensure it's after the +bind in case they arrive in the same frame
                                Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
                }
                return;
@@ -2010,7 +2010,7 @@ Key_Event (int key, int ascii, qbool down)
        {
                if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
                {
-                       Cbuf_AddText(cmd, "toggleconsole\n");  // Deferred to next frame so we're not sending the text event to the console.
+                       Cbuf_InsertText(cmd, "toggleconsole\n");  // Deferred to next frame so we're not sending the text event to the console.
                        tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
                        return;
                }
@@ -2052,14 +2052,14 @@ Key_Event (int key, int ascii, qbool down)
                                if(keydown[key] == 1 && down)
                                {
                                        // button commands add keynum as a parm
+                                       // prepend to avoid delays from `wait` commands added by other sources
                                        if (bind[0] == '+')
-                                               Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
+                                               Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
                                        else
-                                       {
-                                               Cbuf_AddText (cmd, bind);
-                                               Cbuf_AddText (cmd, "\n");
-                                       }
-                               } else if(bind[0] == '+' && !down && keydown[key] == 0)
+                                               Cbuf_InsertText(cmd, bind);
+                               }
+                               else if(bind[0] == '+' && !down && keydown[key] == 0)
+                                       // append -bind to ensure it's after the +bind in case they arrive in the same frame
                                        Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
                        }
                        break;