diff options
author | William Wennerström <william@optmzr.se> | 2019-07-13 19:08:10 +0200 |
---|---|---|
committer | William Wennerström <william@optmzr.se> | 2019-07-20 10:38:22 +0200 |
commit | 0c10a699f2be44665c6e7aa7ec82c0b07a71d743 (patch) | |
tree | 461073aca5fdefc72987759b662bfd95ffbeeb80 /src/tools/autocomplete.c | |
parent | 63552720916dbe82cdb001eee74b7c08723b823a (diff) | |
download | profani-tty-0c10a699f2be44665c6e7aa7ec82c0b07a71d743.tar.gz |
Always check for directory changes with sendfile auto completion
Instead of only checking for files when 'last_directory' has changed, do it every time. Add autocomplete_update function that updates the items while retaining last_found and search_str. Fixes #1099
Diffstat (limited to 'src/tools/autocomplete.c')
-rw-r--r-- | src/tools/autocomplete.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 79312e53..03a30553 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -66,8 +66,10 @@ void autocomplete_clear(Autocomplete ac) { if (ac) { - g_list_free_full(ac->items, free); - ac->items = NULL; + if (ac->items) { + g_list_free_full(ac->items, free); + ac->items = NULL; + } autocomplete_reset(ac); } @@ -102,6 +104,35 @@ autocomplete_length(Autocomplete ac) } void +autocomplete_update(Autocomplete ac, char **items) +{ + gchar *last_found = NULL; + gchar *search_str = NULL; + + if (ac->last_found) { + last_found = strdup(ac->last_found->data); + } + + if (ac->search_str) { + search_str = strdup(ac->search_str); + } + + autocomplete_clear(ac); + autocomplete_add_all(ac, items); + + if (last_found) { + // NULL if last_found was removed on update. + ac->last_found = g_list_find_custom(ac->items, last_found, (GCompareFunc)strcmp); + free(last_found); + } + + if (search_str) { + ac->search_str = strdup(search_str); + free(search_str); + } +} + +void autocomplete_add(Autocomplete ac, const char *item) { if (ac) { |