diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-05-12 17:53:02 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-05-12 17:53:02 +0200 |
commit | adbfd276604bc8025e439ab0ec7345d26a8bc4e8 (patch) | |
tree | 9b47499aee598263de06ba56545c5121a15d9f19 | |
parent | 6d7f10ef2010a7b0c31712e06d7db66c3ab6a2ff (diff) | |
download | weechat-adbfd276604bc8025e439ab0ec7345d26a8bc4e8.zip |
core: fix completion after newline in input (closes #1925)
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 17 |
2 files changed, 11 insertions, 7 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 9a677a181..c10192dc1 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -52,6 +52,7 @@ New features:: Bug fixes:: + * core: fix completion after newline in input (issue #1925) * core: display a specific error when trying to bind a key without area in mouse context * core: fix display of key with command `/key bindctxt <context> <key>` * core: fix default value of bar options (issue #846) diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index eccd8366f..2b2c4a3be 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -812,7 +812,7 @@ gui_completion_find_context (struct t_gui_completion *completion, const char *data, int pos) { int i, size, command_arg, pos_start, pos_end; - const char *ptr_command, *ptr_data, *prev_char; + const char *ptr_command, *ptr_data, *ptr_space, *ptr_newline, *prev_char; /* look for context */ gui_completion_free_data (completion); @@ -845,12 +845,15 @@ gui_completion_find_context (struct t_gui_completion *completion, ptr_data = data; while (ptr_data && (ptr_data < data + pos)) { - ptr_data = strchr (ptr_data, ' '); + ptr_space = strchr (ptr_data, ' '); + ptr_newline = strchr (ptr_data, '\n'); + ptr_data = (ptr_newline && (!ptr_space || (ptr_newline < ptr_space))) ? + ptr_newline : ptr_space; if (!ptr_data) break; if (ptr_data < data + pos) { - while ((ptr_data < data + pos) && (ptr_data[0] == ' ')) + while ((ptr_data < data + pos) && ((ptr_data[0] == ' ') || (ptr_data[0] == '\n'))) { ptr_data++; } @@ -907,10 +910,10 @@ gui_completion_find_context (struct t_gui_completion *completion, pos_start = i; if (data[i] == ' ') { - if ((i > 0) && (data[i-1] != ' ')) + if ((i > 0) && (data[i - 1] != ' ') && (data[i - 1] != '\n')) { i--; - while ((i >= 0) && (data[i] != ' ')) + while ((i >= 0) && (data[i] != ' ') && (data[i] != '\n')) { i--; } @@ -919,7 +922,7 @@ gui_completion_find_context (struct t_gui_completion *completion, } else { - while ((i >= 0) && (data[i] != ' ')) + while ((i >= 0) && (data[i] != ' ') && (data[i] != '\n')) { i--; } @@ -934,7 +937,7 @@ gui_completion_find_context (struct t_gui_completion *completion, { /* base word stops after first space found (on or after cursor) */ i = pos; - while ((i < size) && (data[i] != ' ')) + while ((i < size) && (data[i] != ' ') && (data[i] != '\n')) { i++; } |