]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Add #N SHIFT+TAB completion for player# names des/shifttab_completion 164/head
authorDes <xon@damianv.com.ar>
Fri, 16 Aug 2024 22:11:16 +0000 (19:11 -0300)
committerDes <xon@damianv.com.ar>
Sun, 15 Sep 2024 16:03:30 +0000 (13:03 -0300)
console.c
console.h
keys.c

index 09c64a676c7a79dfa3a8f4fa0d6b61440df61d35..f0dd9e32759b055bba4035b6d26e84ef10f3d6dc 100644 (file)
--- a/console.c
+++ b/console.c
@@ -2517,12 +2517,13 @@ static int Nicks_strncasecmp(char *a, char *b, unsigned int a_len)
 
    Count the number of possible nicks to complete
  */
-static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qbool isCon)
+static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qbool isCon, qbool only_pnumbers)
 {
        char name[MAX_SCOREBOARDNAME];
        int i, p;
        int match;
        int spos;
+       int digits = 0;
        int count = 0;
 
        if(!con_nickcompletion.integer)
@@ -2559,7 +2560,17 @@ static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qbool isCon
                        }
                        if(isCon && spos == 0)
                                break;
-                       if(Nicks_strncasecmp(line+spos, name, pos-spos) == 0)
+                       if(only_pnumbers)
+                       {
+                               if(line[spos] == '#')
+                               {
+                                       digits = (int) strspn(line+spos+1, "0123456789");
+                                       //  word lenght EQUAL digits count OR digits count + 1 trailing space
+                                       if(((pos)-(spos+1)) == (line[pos-1] == ' ' ? digits+1 : digits) && p == (atoi(line+spos+1)-1))
+                                               match = spos;
+                               }
+                       }
+                       else if(Nicks_strncasecmp(line+spos, name, pos-spos) == 0)
                                match = spos;
                        --spos;
                }
@@ -2872,7 +2883,7 @@ static size_t Con_EscapeSpaces(char *dst, const char *src, size_t dsize)
        Directory support by divVerent
        Escaping support by bones_was_here
 */
-int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console)
+int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console, qbool only_pnumbers)
 {
        const char *text = "";
        char *s;
@@ -2918,7 +2929,7 @@ int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console)
        line[linepos] = 0; //hide them
 
        c = v = a = n = cmd_len = 0;
-       if (!is_console)
+       if (!is_console || only_pnumbers)
                goto nicks;
 
        space = strchr(line + 1, ' ');
@@ -3137,7 +3148,7 @@ int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console)
        }
 
 nicks:
-       n = Nicks_CompleteCountPossible(line, linepos, s, is_console);
+       n = Nicks_CompleteCountPossible(line, linepos, s, is_console, only_pnumbers);
        if (n)
        {
                Con_Printf("\n%i possible nick%s\n", n, (n > 1) ? "s: " : ":");
index 7ea1ecd06823c3025d118eca1602351eee539e60..503f14e56200aaf5ed10fce26e953a5ad2e7f146 100644 (file)
--- a/console.h
+++ b/console.h
@@ -80,7 +80,7 @@ size_t GetMapList (const char *s, char *completedname, int completednamebuffersi
 /// or to list possible matches grouped by type
 /// (i.e. will display possible variables, aliases, commands
 /// that match what they've typed so far)
-int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console);
+int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console, qbool only_pnumbers);
 
 /// Generic libs/util/console.c function to display a list
 /// formatted in columns on the console
diff --git a/keys.c b/keys.c
index 0762490e5fee4b634e68cb02191a0bf13b1f9660..0b9f60c16295e3521e84a75c1de25e42e976c1de 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -864,8 +864,10 @@ int Key_Parse_CommonKeys(cmd_state_t *cmd, qbool is_console, int key, int unicod
                        return linepos;
                }
 
+               if (KM_SHIFT) // only complete player references #N as names
+                       return Con_CompleteCommandLine(cmd, is_console, true);
                if (KM_NONE)
-                       return Con_CompleteCommandLine(cmd, is_console);
+                       return Con_CompleteCommandLine(cmd, is_console, false);
        }
 
        // Advanced Console Editing by Radix radix@planetquake.com