diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-08-12 17:38:59 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-08-12 17:38:59 +0200 |
commit | 94acf64f8cd35162d04fcb4ad63c5dfa34f8d432 (patch) | |
tree | 67d6b4da436a89defc827f0f5e3e18af76ff7ac6 /src | |
parent | 50ac22c16ed5954ffb4100c970017fe75f44fb20 (diff) | |
download | weechat-94acf64f8cd35162d04fcb4ad63c5dfa34f8d432.zip |
Use similar behaviour for keys bound to local or global history (bug #30759)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 8 | ||||
-rw-r--r-- | src/gui/gui-input.c | 293 | ||||
-rw-r--r-- | src/gui/gui-input.h | 8 |
3 files changed, 153 insertions, 156 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 313fb4074..2c33bcd07 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1928,13 +1928,13 @@ command_input (void *data, struct t_gui_buffer *buffer, else if (string_strcasecmp (argv[1], "move_next_word") == 0) gui_input_move_next_word (gui_current_window->buffer); else if (string_strcasecmp (argv[1], "history_previous") == 0) - gui_input_history_previous (gui_current_window); + gui_input_history_local_previous (gui_current_window); else if (string_strcasecmp (argv[1], "history_next") == 0) - gui_input_history_next (gui_current_window); + gui_input_history_local_next (gui_current_window); else if (string_strcasecmp (argv[1], "history_global_previous") == 0) - gui_input_history_global_previous (gui_current_window->buffer); + gui_input_history_global_previous (gui_current_window); else if (string_strcasecmp (argv[1], "history_global_next") == 0) - gui_input_history_global_next (gui_current_window->buffer); + gui_input_history_global_next (gui_current_window); else if (string_strcasecmp (argv[1], "jump_smart") == 0) gui_input_jump_smart (gui_current_window); else if (string_strcasecmp (argv[1], "jump_last_buffer") == 0) diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index 8b1f94227..5bbdda9a6 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -899,202 +899,199 @@ gui_input_move_next_word (struct t_gui_buffer *buffer) } /* - * gui_input_history_previous: recall previous command (default key: up) + * gui_input_history_previous: recall previous command from local or global + * history */ void -gui_input_history_previous (struct t_gui_window *window) +gui_input_history_previous (struct t_gui_window *window, + struct t_gui_history *history, + struct t_gui_history **ptr_history) { - if (window->buffer->input) + if (!window->buffer->input) + return; + + if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) { - if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + if (*ptr_history) + { + if (!(*ptr_history)->next_history) + return; + *ptr_history = (*ptr_history)->next_history; + } + if (!(*ptr_history)) + *ptr_history = history; + + if (!(*ptr_history)) + return; + + /* bash/readline like use of history */ + if (window->buffer->input_buffer_size > 0) { - if (window->buffer->ptr_history) + if ((*ptr_history)->prev_history) { - if (!window->buffer->ptr_history->next_history) - return; - window->buffer->ptr_history = window->buffer->ptr_history->next_history; - if (!window->buffer->ptr_history) - window->buffer->ptr_history = window->buffer->history; + /* replace text in history with current input */ + window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; + if ((*ptr_history)->prev_history->text) + free ((*ptr_history)->prev_history->text); + (*ptr_history)->prev_history->text = + strdup (window->buffer->input_buffer); } else - window->buffer->ptr_history = window->buffer->history; - if (window->buffer->ptr_history) { - /* bash/readline like use of history */ - if (window->buffer->ptr_history->prev_history == NULL) - { - if (window->buffer->input_buffer_size > 0) - { - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - gui_history_add (window->buffer, - window->buffer->input_buffer); - } - } - else - { - if (window->buffer->input_buffer_size > 0) - { - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - if (window->buffer->ptr_history->prev_history->text) - free(window->buffer->ptr_history->prev_history->text); - window->buffer->ptr_history->prev_history->text = - strdup (window->buffer->input_buffer); - } - } - window->buffer->input_buffer_size = - strlen (window->buffer->ptr_history->text); - window->buffer->input_buffer_length = - utf8_strlen (window->buffer->ptr_history->text); - gui_input_optimize_size (window->buffer); - window->buffer->input_buffer_pos = window->buffer->input_buffer_length; - window->buffer->input_buffer_1st_display = 0; - strcpy (window->buffer->input_buffer, - window->buffer->ptr_history->text); + /* add current input in history */ + window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; + gui_history_add (window->buffer, + window->buffer->input_buffer); } - gui_input_text_changed_modifier_and_signal (window->buffer, 0); - gui_buffer_undo_free_all (window->buffer); - } - else - { - /* search backward in buffer history */ - window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD; - (void) gui_window_search_text (window); } + window->buffer->input_buffer_size = + strlen ((*ptr_history)->text); + window->buffer->input_buffer_length = + utf8_strlen ((*ptr_history)->text); + gui_input_optimize_size (window->buffer); + window->buffer->input_buffer_pos = window->buffer->input_buffer_length; + window->buffer->input_buffer_1st_display = 0; + strcpy (window->buffer->input_buffer, (*ptr_history)->text); + gui_input_text_changed_modifier_and_signal (window->buffer, 0); + gui_buffer_undo_free_all (window->buffer); + } + else + { + /* search backward in buffer history */ + window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD; + (void) gui_window_search_text (window); } } /* - * gui_input_history_next: recall next command (default key: down) + * gui_input_history_next: recall next command from local or global history */ void -gui_input_history_next (struct t_gui_window *window) +gui_input_history_next (struct t_gui_window *window, + struct t_gui_history *history, + struct t_gui_history **ptr_history) { - if (window->buffer->input) + int input_changed; + + /* make C compiler happy */ + (void) history; + + input_changed = 0; + + if (!window->buffer->input) + return; + + if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) { - if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + if (*ptr_history) { - if (window->buffer->ptr_history) + *ptr_history = (*ptr_history)->prev_history; + if (*ptr_history) { - window->buffer->ptr_history = - window->buffer->ptr_history->prev_history; - if (window->buffer->ptr_history) - { - window->buffer->input_buffer_size = - strlen (window->buffer->ptr_history->text); - window->buffer->input_buffer_length = - utf8_strlen (window->buffer->ptr_history->text); - } - else - { - window->buffer->input_buffer[0] = '\0'; - window->buffer->input_buffer_size = 0; - window->buffer->input_buffer_length = 0; - } - gui_input_optimize_size (window->buffer); - window->buffer->input_buffer_pos = - window->buffer->input_buffer_length; - window->buffer->input_buffer_1st_display = 0; - if (window->buffer->ptr_history) - { - strcpy (window->buffer->input_buffer, - window->buffer->ptr_history->text); - } + window->buffer->input_buffer_size = + strlen ((*ptr_history)->text); + window->buffer->input_buffer_length = + utf8_strlen ((*ptr_history)->text); } else { - /* add line to history then clear input */ - if (window->buffer->input_buffer_size > 0) - { - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - gui_history_add (window->buffer, - window->buffer->input_buffer); - window->buffer->input_buffer[0] = '\0'; - window->buffer->input_buffer_size = 0; - window->buffer->input_buffer_length = 0; - window->buffer->input_buffer_pos = 0; - window->buffer->input_buffer_1st_display = 0; - gui_input_optimize_size (window->buffer); - } + window->buffer->input_buffer[0] = '\0'; + window->buffer->input_buffer_size = 0; + window->buffer->input_buffer_length = 0; } - gui_input_text_changed_modifier_and_signal (window->buffer, 0); - gui_buffer_undo_free_all (window->buffer); + gui_input_optimize_size (window->buffer); + window->buffer->input_buffer_pos = + window->buffer->input_buffer_length; + window->buffer->input_buffer_1st_display = 0; + if (*ptr_history) + { + strcpy (window->buffer->input_buffer, (*ptr_history)->text); + } + input_changed = 1; } else { - /* search forward in buffer history */ - window->buffer->text_search = GUI_TEXT_SEARCH_FORWARD; - (void) gui_window_search_text (window); + /* add line to history then clear input */ + if (window->buffer->input_buffer_size > 0) + { + window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; + gui_history_add (window->buffer, + window->buffer->input_buffer); + window->buffer->input_buffer[0] = '\0'; + window->buffer->input_buffer_size = 0; + window->buffer->input_buffer_length = 0; + window->buffer->input_buffer_pos = 0; + window->buffer->input_buffer_1st_display = 0; + gui_input_optimize_size (window->buffer); + input_changed = 1; + } } + if (input_changed) + { + gui_input_text_changed_modifier_and_signal (window->buffer, 0); + gui_buffer_undo_free_all (window->buffer); + } + } + else + { + /* search forward in buffer history */ + window->buffer->text_search = GUI_TEXT_SEARCH_FORWARD; + (void) gui_window_search_text (window); } } /* - * gui_input_history_global_previous: recall previous command in global history + * gui_input_history_local_previous: recall previous command from local history + * (default key: up) + */ + +void +gui_input_history_local_previous (struct t_gui_window *window) +{ + gui_input_history_previous (window, + window->buffer->history, + &(window->buffer->ptr_history)); +} + +/* + * gui_input_history_local_next: recall next command from local history + * (default key: down) + */ + +void +gui_input_history_local_next (struct t_gui_window *window) +{ + gui_input_history_next (window, + window->buffer->history, + &(window->buffer->ptr_history)); +} + +/* + * gui_input_history_global_previous: recall previous command from global history * (default key: ctrl-up) */ void -gui_input_history_global_previous (struct t_gui_buffer *buffer) +gui_input_history_global_previous (struct t_gui_window *window) { - if (buffer->input && (buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) - { - if (history_global_ptr) - { - history_global_ptr = history_global_ptr->next_history; - if (!history_global_ptr) - history_global_ptr = history_global; - } - else - history_global_ptr = history_global; - if (history_global_ptr) - { - buffer->input_buffer_size = strlen (history_global_ptr->text); - buffer->input_buffer_length = utf8_strlen (history_global_ptr->text); - gui_input_optimize_size (buffer); - buffer->input_buffer_pos = buffer->input_buffer_length; - buffer->input_buffer_1st_display = 0; - strcpy (buffer->input_buffer, history_global_ptr->text); - gui_input_text_changed_modifier_and_signal (buffer, 0); - gui_buffer_undo_free_all (buffer); - } - } + gui_input_history_previous (window, + history_global, + &history_global_ptr); } /* - * gui_history_global_next: recall next command in global history + * gui_history_global_next: recall next command from global history * (default key: ctrl-down) */ void -gui_input_history_global_next (struct t_gui_buffer *buffer) +gui_input_history_global_next (struct t_gui_window *window) { - if (buffer->input && (buffer->text_search == GUI_TEXT_SEARCH_DISABLED) - && history_global_ptr) - { - history_global_ptr = history_global_ptr->prev_history; - if (history_global_ptr) - { - buffer->input_buffer_size = strlen (history_global_ptr->text); - buffer->input_buffer_length = utf8_strlen (history_global_ptr->text); - } - else - { - buffer->input_buffer[0] = '\0'; - buffer->input_buffer_size = 0; - buffer->input_buffer_length = 0; - } - gui_input_optimize_size (buffer); - buffer->input_buffer_pos = buffer->input_buffer_length; - buffer->input_buffer_1st_display = 0; - if (history_global_ptr) - { - strcpy (buffer->input_buffer, history_global_ptr->text); - } - gui_input_text_changed_modifier_and_signal (buffer, 0); - gui_buffer_undo_free_all (buffer); - } + gui_input_history_next (window, + history_global, + &history_global_ptr); } /* diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h index 03631f412..cd0ac33eb 100644 --- a/src/gui/gui-input.h +++ b/src/gui/gui-input.h @@ -58,10 +58,10 @@ extern void gui_input_move_previous_char (struct t_gui_buffer *buffer); extern void gui_input_move_next_char (struct t_gui_buffer *buffer); extern void gui_input_move_previous_word (struct t_gui_buffer *buffer); extern void gui_input_move_next_word (struct t_gui_buffer *buffer); -extern void gui_input_history_previous (struct t_gui_window *window); -extern void gui_input_history_next (struct t_gui_window *window); -extern void gui_input_history_global_previous (struct t_gui_buffer *buffer); -extern void gui_input_history_global_next (struct t_gui_buffer *buffer); +extern void gui_input_history_local_previous (struct t_gui_window *window); +extern void gui_input_history_local_next (struct t_gui_window *window); +extern void gui_input_history_global_previous (struct t_gui_window *window); +extern void gui_input_history_global_next (struct t_gui_window *window); extern void gui_input_jump_smart (struct t_gui_window *window); extern void gui_input_jump_last_buffer (struct t_gui_window *window); extern void gui_input_jump_previously_visited_buffer (struct t_gui_window *window); |