summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2018-01-03 15:35:18 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2018-01-03 15:35:18 +0100
commit2361d4b1e5d38701f35146219ceddd318ac4e645 (patch)
tree69e1467474a050c8d1e1fb875fc54a06b0d5a0ef /src
parente405330e04dc344797f00c12cf8fd7f63b17e0e4 (diff)
downloadirssi-2361d4b1e5d38701f35146219ceddd318ac4e645.zip
rewrite completion code and check for direct match of separator
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/completion.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c
index e78fe7d5..fd452e5c 100644
--- a/src/fe-common/core/completion.c
+++ b/src/fe-common/core/completion.c
@@ -187,12 +187,18 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i
char *old;
old = linestart;
- linestart = *linestart == '\0' ?
- g_strdup(word) :
- g_strdup_printf("%s%c%s",
- /* do not accidentally duplicate the word separator */
- line == wordstart - 1 ? "" : linestart,
- old_wordstart[-1], word);
+ /* we want to move word into linestart */
+ if (*linestart == '\0') {
+ linestart = g_strdup(word);
+ } else {
+ GString *str = g_string_new(linestart);
+ if (old_wordstart[-1] != str->str[str->len - 1]) {
+ /* do not accidentally duplicate the word separator */
+ g_string_append_c(str, old_wordstart[-1]);
+ }
+ g_string_append(str, word);
+ linestart = g_string_free(str, FALSE);
+ }
g_free(old);
g_free(word);