From 9b86146de2816bd09919b0372f8e8b88bd9e9369 Mon Sep 17 00:00:00 2001 From: ply Date: Fri, 23 Sep 2011 13:38:56 +0300 Subject: [PATCH] Ticket #2614: Editor word completion should ignore the current word Currently the completion considers the word the cursor is on as a possible completion, but this is quite annoying if the cursor is inside the word. Such completion effectively inserts the rest of the word one more time, so CamelCase becomes CamelCaseCase. If this is the only match, it completes automatically, which is even worse. The current word shouldn't be used for completion. Signed-off-by: Slava Zanko --- src/editor/editcmd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index a852ea533..f09f68e25 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1028,7 +1028,7 @@ edit_find_word_start (WEdit * edit, long *word_start, gsize * word_len) /* --------------------------------------------------------------------------------------------- */ /** collect the possible completions */ static gsize -edit_collect_completions (WEdit * edit, long start, gsize word_len, +edit_collect_completions (WEdit * edit, long word_start, gsize word_len, char *match_expr, struct selection *compl, gsize * num) { gsize len = 0; @@ -1038,7 +1038,7 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len, GString *temp; mc_search_t *srch; - long last_byte; + long last_byte, start = -1; srch = mc_search_new (match_expr, -1); if (srch == NULL) @@ -1051,7 +1051,7 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len, } else { - last_byte = start; + last_byte = word_start; } srch->search_type = MC_SEARCH_T_REGEX; @@ -1059,7 +1059,6 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len, srch->search_fn = edit_search_cmd_callback; /* collect max MAX_WORD_COMPLETIONS completions */ - start = -1; while (1) { /* get next match */ @@ -1074,9 +1073,17 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len, skip = edit_get_byte (edit, start + i); if (isspace (skip)) continue; + + /* skip current word */ + if (start + (long) i == word_start) + break; + g_string_append_c (temp, skip); } + if (temp->len == 0) + continue; + skip = 0; for (i = 0; i < (gsize) * num; i++) -- 2.11.4.GIT