From d4b7da3740c18346732f7905fc87b631042145d6 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Wed, 12 Mar 2025 23:28:37 +0000 Subject: [PATCH] Fix tab completion FossilOrigin-Name: 2200947ce957ddb35e68f3d631cc4b7171394ea06302fdb9ce624f1aebf8584c --- src/commands.mm | 29 +++++++++++------------------ src/protos.h | 2 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/commands.mm b/src/commands.mm index bbeaf43..3eb0898 100644 --- a/src/commands.mm +++ b/src/commands.mm @@ -298,36 +298,29 @@ resetcomplete() } void -complete(OFString *s_) +complete(OFMutableString *s) { @autoreleasepool { - std::unique_ptr copy(strdup(s_.UTF8String)); - char *s = copy.get(); + if (![s hasPrefix:@"/"]) + [s insertString:@"/" atIndex:0]; - if (*s != '/') { - string t; - strcpy_s(t, s); - strcpy_s(s, "/"); - strcat_s(s, t); - } - - if (!s[1]) + if (s.length == 1) return; if (!completesize) { - completesize = strlen(s) - 1; + completesize = s.length - 1; completeidx = 0; } __block int idx = 0; [identifiers enumerateKeysAndObjectsUsingBlock:^( OFString *name, Identifier *identifier, bool *stop) { - if (strncmp(identifier.name.UTF8String, s + 1, - completesize) == 0 && - idx++ == completeidx) { - strcpy_s(s, "/"); - strcat_s(s, identifier.name.UTF8String); - } + if (strncmp(identifier.name.UTF8String, + s.UTF8String + 1, completesize) == 0 && + idx++ == completeidx) + [s replaceCharactersInRange:OFMakeRange( + 1, s.length - 1) + withString:identifier.name]; }]; completeidx++; diff --git a/src/protos.h b/src/protos.h index 6f9c9c0..b863eb5 100644 --- a/src/protos.h +++ b/src/protos.h @@ -11,7 +11,7 @@ extern int execute(OFString *p, bool down = true); extern void exec(OFString *cfgfile); extern bool execfile(OFIRI *cfgfile); extern void resetcomplete(); -extern void complete(OFString *s); +extern void complete(OFMutableString *s); extern void alias(OFString *name, OFString *action); extern OFString *getalias(OFString *name); extern void writecfg();