diff options
-rw-r--r-- | src/fe-common/core/command-history.c | 17 | ||||
-rw-r--r-- | src/fe-common/core/command-history.h | 1 | ||||
-rw-r--r-- | src/fe-text/gui-readline.c | 13 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c index a6a800d3..32d7adaa 100644 --- a/src/fe-common/core/command-history.c +++ b/src/fe-common/core/command-history.c @@ -307,6 +307,23 @@ const char *command_global_history_next(WINDOW_REC *window, const char *text) return command_history_next_int(window, text, TRUE); } +const char *command_history_delete_current(WINDOW_REC *window, const char *text) +{ + HISTORY_REC *history; + GList *pos; + + history = command_history_current(window); + pos = history->pos; + + if (pos != NULL && g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) == 0) { + ((HISTORY_ENTRY_REC *)pos->data)->history->lines--; + history_list_delete_link_and_destroy(pos); + } + + history->redo = 0; + return history->pos == NULL ? "" : ((HISTORY_ENTRY_REC *)history->pos->data)->text; +} + void command_history_clear_pos_func(HISTORY_REC *history, gpointer user_data) { history->pos = NULL; diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h index dc4d46da..ed093415 100644 --- a/src/fe-common/core/command-history.h +++ b/src/fe-common/core/command-history.h @@ -40,6 +40,7 @@ const char *command_history_prev(WINDOW_REC *window, const char *text); const char *command_history_next(WINDOW_REC *window, const char *text); const char *command_global_history_prev(WINDOW_REC *window, const char *text); const char *command_global_history_next(WINDOW_REC *window, const char *text); +const char *command_history_delete_current(WINDOW_REC *window, const char *text); void command_history_clear_pos(WINDOW_REC *window); diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 0528ed94..b3a78396 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -552,6 +552,17 @@ static void key_forward_global_history(void) g_free(line); } +static void key_erase_history_entry(void) +{ + const char *text; + char *line; + + line = gui_entry_get_text(active_entry); + text = command_history_delete_current(active_win, line); + gui_entry_set_text(active_entry, text); + g_free(line); +} + static void key_beginning_of_line(void) { gui_entry_set_pos(active_entry, 0); @@ -1243,6 +1254,7 @@ void gui_readline_init(void) key_bind("forward_history", "Go forward one line in the history", "down", NULL, (SIGNAL_FUNC) key_forward_history); key_bind("backward_global_history", "Go back one line in the global history", "cup", NULL, (SIGNAL_FUNC) key_backward_global_history); key_bind("forward_global_history", "Go forward one line in the global history", "cdown", NULL, (SIGNAL_FUNC) key_forward_global_history); + key_bind("erase_history_entry", "Erase the currently active entry from the history", NULL, NULL, (SIGNAL_FUNC) key_erase_history_entry); /* line editing */ key_bind("backspace", "Delete the previous character", "backspace", NULL, (SIGNAL_FUNC) key_backspace); @@ -1338,6 +1350,7 @@ void gui_readline_deinit(void) key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history); key_unbind("backward_global_history", (SIGNAL_FUNC) key_backward_global_history); key_unbind("forward_global_history", (SIGNAL_FUNC) key_forward_global_history); + key_unbind("erase_history_entry", (SIGNAL_FUNC) key_erase_history_entry); key_unbind("backspace", (SIGNAL_FUNC) key_backspace); key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character); |