1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 14:57:45 +02:00

fix buggy path autocomplete behaviour

This commit is contained in:
Jfreegman 2014-07-28 01:33:12 -04:00
parent b18a67d656
commit 94a8ce5aa8
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
3 changed files with 15 additions and 19 deletions

View File

@ -202,7 +202,7 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
}
/* transforms a sendfile tab complete contaning the shorthand "~/" into the full home directory.*/
static void complt_home_dir(ToxWindow *self, char *path)
static void complt_home_dir(ToxWindow *self, char *path, int pathsize)
{
ChatContext *ctx = self->chatwin;
@ -210,8 +210,8 @@ static void complt_home_dir(ToxWindow *self, char *path)
get_home_dir(homedir, sizeof(homedir));
char newline[MAX_STR_SIZE];
const char *isqt = !strchr(path, '\"') ? "\"" : "";
snprintf(newline, sizeof(newline), "/sendfile %s%s/", isqt, homedir);
snprintf(newline, sizeof(newline), "/sendfile \"%s%s", homedir, path + 1);
snprintf(path, pathsize, "%s", &newline[11]);
wchar_t wline[MAX_STR_SIZE];
@ -231,22 +231,20 @@ static void complt_home_dir(ToxWindow *self, char *path)
/* attempts to match /sendfile "<incomplete-dir>" line to matching directories.
if only one match, auto-complete line.
return diff between old len and new len of ctx->line, -1 if no matches
*/
#define MAX_DIRS 256
return diff between old len and new len of ctx->line, -1 if no matches or > 1 match */
#define MAX_DIRS 512
int dir_match(ToxWindow *self, Tox *m, wchar_t *line)
int dir_match(ToxWindow *self, Tox *m, const wchar_t *line)
{
char b_path[MAX_STR_SIZE];
char b_name[MAX_STR_SIZE];
const wchar_t *tmpline = &line[11]; /* start after "/sendfile \"" */
if (wcs_to_mbs_buf(b_path, line, sizeof(b_path)) == -1)
if (wcs_to_mbs_buf(b_path, tmpline, sizeof(b_path)) == -1)
return -1;
if (!strncmp(b_path, "\"~/", 3) || !strncmp(b_path, "~/", 2)) {
complt_home_dir(self, b_path);
return -1;
}
if (!strncmp(b_path, "~/", 2))
complt_home_dir(self, b_path, sizeof(b_path));
int si = char_rfind(b_path, '/', strlen(b_path));

View File

@ -33,11 +33,10 @@
Returns the difference between the old len and new len of line on success, -1 if error */
int complete_line(ToxWindow *self, const void *list, int n_items, int size);
/* matches /sendfile "<incomplete-dir>" line to matching directories.
/* attempts to match /sendfile "<incomplete-dir>" line to matching directories.
if only one match, auto-complete line.
return diff between old len and new len of ctx->line, or -1 if no matches
*/
if only one match, auto-complete line.
return diff between old len and new len of ctx->line, -1 if no matches or > 1 match */
int dir_match(ToxWindow *self, Tox *m, const wchar_t *line);
#endif /* #define _autocomplete_h */

View File

@ -756,10 +756,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
if (key == '\t' && ctx->len > 1 && ctx->line[0] == '/') { /* TAB key: auto-complete */
int diff = -1;
int sf_len = 11;
if (wcsncmp(ctx->line, L"/sendfile \"", sf_len) == 0) {
diff = dir_match(self, m, &ctx->line[sf_len]);
if (wcsncmp(ctx->line, L"/sendfile \"", wcslen(L"/sendfile \"")) == 0) {
diff = dir_match(self, m, ctx->line);
} else {
diff = complete_line(self, chat_cmd_list, AC_NUM_CHAT_COMMANDS, MAX_CMDNAME_SIZE);
}