diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index 808f655a2..6f7b0f4bb 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -31,7 +31,7 @@ struct t_gui_buffer *fset_buffer = NULL; -int fset_buffer_selected_line = -1; +int fset_buffer_selected_line = 0; struct t_hashtable *fset_buffer_hashtable_pointers = NULL; struct t_hashtable *fset_buffer_hashtable_extra_vars = NULL; char *fset_buffer_columns[] = { "name", "parent_name", "type", "default_value", @@ -285,10 +285,7 @@ fset_buffer_refresh (int clear) num_options = weechat_arraylist_size (fset_options); if (clear) - { weechat_buffer_clear (fset_buffer); - fset_buffer_selected_line = (num_options > 0) ? 0 : -1; - } snprintf (str_title, sizeof (str_title), _("Fast Set")); weechat_buffer_set (fset_buffer, "title", str_title); diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index e47b637e8..081092595 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -93,8 +93,7 @@ fset_command_fset (const void *pointer, void *data, value = 1; } num_options = weechat_arraylist_size (fset_options); - if ((fset_buffer_selected_line >= 0) - && (num_options > 0)) + if (num_options > 0) { line = fset_buffer_selected_line - value; if (line < 0) @@ -122,8 +121,7 @@ fset_command_fset (const void *pointer, void *data, value = 1; } num_options = weechat_arraylist_size (fset_options); - if ((fset_buffer_selected_line >= 0) - && (num_options > 0)) + if (num_options > 0) { line = fset_buffer_selected_line + value; if (line >= num_options) diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index e0429ffe0..ddf3546be 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -564,6 +564,7 @@ fset_option_get_options () struct t_config_file *ptr_config; struct t_config_section *ptr_section; struct t_config_option *ptr_option; + int num_options; weechat_arraylist_clear (fset_options); weechat_hashtable_remove_all (fset_option_max_length_field); @@ -593,6 +594,12 @@ fset_option_get_options () ptr_config = weechat_hdata_move (fset_hdata_config_file, ptr_config, 1); } + + num_options = weechat_arraylist_size (fset_options); + if (num_options == 0) + fset_buffer_selected_line = 0; + else if (fset_buffer_selected_line >= num_options) + fset_buffer_selected_line = num_options - 1; } /* @@ -615,6 +622,7 @@ fset_option_set_filter (const char *filter) void fset_option_filter_options (const char *search) { + fset_buffer_selected_line = 0; fset_option_set_filter (search); fset_option_get_options (); fset_buffer_refresh (1); @@ -633,7 +641,7 @@ fset_option_config_cb (const void *pointer, const char *ptr_info; struct t_fset_option *ptr_fset_option; struct t_config_option *ptr_option; - int line, num_options; + int line, num_options, full_refresh; /* make C compiler happy */ (void) pointer; @@ -649,6 +657,8 @@ fset_option_config_cb (const void *pointer, if (ptr_info && (strcmp (ptr_info, "1") == 0)) return WEECHAT_RC_OK; + full_refresh = 0; + ptr_fset_option = fset_option_search_by_name (option, &line); if (ptr_fset_option) { @@ -660,23 +670,36 @@ fset_option_config_cb (const void *pointer, } else { - /* option removed, refresh the whole buffer */ - fset_buffer_refresh (1); + /* option removed: get options and refresh the whole buffer */ + full_refresh = 1; } } - - num_options = weechat_arraylist_size (fset_options); - for (line = 0; line < num_options; line++) + else { - ptr_fset_option = weechat_arraylist_get (fset_options, line); - if (ptr_fset_option->parent_name - && (strcmp (ptr_fset_option->parent_name, option) == 0)) + /* option added: get options and refresh the whole buffer */ + full_refresh = 1; + } + + if (full_refresh) + { + fset_option_get_options (); + fset_buffer_refresh (1); + } + else + { + num_options = weechat_arraylist_size (fset_options); + for (line = 0; line < num_options; line++) { - ptr_option = weechat_config_get (ptr_fset_option->name); - if (ptr_option) + ptr_fset_option = weechat_arraylist_get (fset_options, line); + if (ptr_fset_option->parent_name + && (strcmp (ptr_fset_option->parent_name, option) == 0)) { - fset_option_set_values (ptr_fset_option, ptr_option); - fset_buffer_display_line (line, ptr_fset_option); + ptr_option = weechat_config_get (ptr_fset_option->name); + if (ptr_option) + { + fset_option_set_values (ptr_fset_option, ptr_option); + fset_buffer_display_line (line, ptr_fset_option); + } } } }