From 4f3e50d6bc5064b05ec891554a287aad247232cf Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 3 Apr 2009 11:55:12 +0200 Subject: [PATCH] Fix bug with nick completion (too many nick completors were added to nick if private was open with nick) --- src/gui/gui-completion.c | 17 +++++++++-- src/gui/gui-input.c | 50 +++++++------------------------- src/plugins/irc/irc-completion.c | 11 ++++--- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 462569cd5..a1ec06246 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -307,6 +307,8 @@ void gui_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where) { + char buffer[512]; + if (!word || !word[0]) return; @@ -316,8 +318,18 @@ gui_completion_list_add (struct t_gui_completion *completion, const char *word, || (!nick_completion && (string_strncasecmp (completion->base_word, word, strlen (completion->base_word)) == 0))) { - weelist_add (completion->completion_list, word, where, - (nick_completion) ? (void *)1 : (void *)0); + if (nick_completion && (completion->base_word_pos == 0)) + { + snprintf (buffer, sizeof (buffer), "%s%s", + word, CONFIG_STRING(config_completion_nick_completor)); + weelist_add (completion->completion_list, buffer, where, + (nick_completion) ? (void *)1 : (void *)0); + } + else + { + weelist_add (completion->completion_list, word, where, + (nick_completion) ? (void *)1 : (void *)0); + } } } @@ -1724,6 +1736,7 @@ gui_completion_print_log (struct t_gui_completion *completion) log_printf (" force_partial_completion: %d", completion->force_partial_completion); log_printf (" completion_list . . . . : 0x%lx", completion->completion_list); log_printf (" word_found. . . . . . . : '%s'", completion->word_found); + log_printf (" word_found_is_nick. . . : %d", completion->word_found_is_nick); log_printf (" position_replace. . . . : %d", completion->position_replace); log_printf (" diff_size . . . . . . . : %d", completion->diff_size); log_printf (" diff_length . . . . . . : %d", completion->diff_length); diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index c049c5b6d..6cfd9f34c 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -363,47 +363,17 @@ gui_input_complete (struct t_gui_buffer *buffer) buffer->completion->position = utf8_real_pos (buffer->input_buffer, buffer->input_buffer_pos); - /* add nick completor if position 0 and completing nick */ - if ((buffer->completion->base_word_pos == 0) - && buffer->completion->word_found_is_nick) + /* add space if needed after completion */ + if (buffer->completion->add_space) { - if (buffer->completion->add_space) - { - if (strncmp (utf8_add_offset (buffer->input_buffer, - buffer->input_buffer_pos), - CONFIG_STRING(config_completion_nick_completor), - strlen (CONFIG_STRING(config_completion_nick_completor))) != 0) - gui_input_insert_string (buffer, - CONFIG_STRING(config_completion_nick_completor), - buffer->input_buffer_pos); - else - buffer->input_buffer_pos += utf8_strlen (CONFIG_STRING(config_completion_nick_completor)); - if (buffer->completion->position >= 0) - buffer->completion->position += strlen (CONFIG_STRING(config_completion_nick_completor)); - if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer, - buffer->input_buffer_pos)] != ' ') - gui_input_insert_string (buffer, " ", - buffer->input_buffer_pos); - else - buffer->input_buffer_pos++; - if (buffer->completion->position >= 0) - buffer->completion->position++; - } - } - else - { - /* add space or completor to the end of completion, if needed */ - if (buffer->completion->add_space) - { - if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer, - buffer->input_buffer_pos)] != ' ') - gui_input_insert_string (buffer, " ", - buffer->input_buffer_pos); - else - buffer->input_buffer_pos++; - if (buffer->completion->position >= 0) - buffer->completion->position++; - } + if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer, + buffer->input_buffer_pos)] != ' ') + gui_input_insert_string (buffer, " ", + buffer->input_buffer_pos); + else + buffer->input_buffer_pos++; + if (buffer->completion->position >= 0) + buffer->completion->position++; } gui_input_text_changed_modifier_and_signal (buffer); } diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index d10f5477a..3ca5d69a2 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -242,7 +242,7 @@ irc_completion_channel_nicks_cb (void *data, const char *completion_item, /* remote nick */ weechat_hook_completion_list_add (completion, ptr_channel->name, - 0, + 1, WEECHAT_LIST_POS_SORT); /* add self nick at the end */ weechat_hook_completion_list_add (completion, @@ -310,7 +310,7 @@ irc_completion_channel_nicks_hosts_cb (void *data, const char *completion_item, case IRC_CHANNEL_TYPE_PRIVATE: weechat_hook_completion_list_add (completion, ptr_channel->name, - 0, + 1, WEECHAT_LIST_POS_SORT); break; } @@ -373,8 +373,11 @@ irc_completion_channels_cb (void *data, const char *completion_item, for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { - weechat_hook_completion_list_add (completion, ptr_channel->name, - 0, WEECHAT_LIST_POS_SORT); + if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) + { + weechat_hook_completion_list_add (completion, ptr_channel->name, + 0, WEECHAT_LIST_POS_SORT); + } } }