From d415350aaf050104d1a8c1d4f4b1179f202aa105 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 5 Jun 2019 19:02:32 +0200 Subject: [PATCH] reader: Add delete-or-exit bind function This is an important binding and should therefore be in C++. --- src/input.cpp | 1 + src/input_common.h | 1 + src/reader.cpp | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/src/input.cpp b/src/input.cpp index 3ee10e3dc..94c9f90b8 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -132,6 +132,7 @@ static const input_function_metadata_t input_function_metadata[] = { {readline_cmd_t::reverse_repeat_jump, L"repeat-jump-reverse"}, {readline_cmd_t::func_and, L"and"}, {readline_cmd_t::expand_abbr, L"expand-abbr"}, + {readline_cmd_t::delete_or_exit, L"delete-or-exit"}, {readline_cmd_t::cancel, L"cancel"}}; static_assert(sizeof(input_function_metadata) / sizeof(input_function_metadata[0]) == diff --git a/src/input_common.h b/src/input_common.h index 6f261242d..4f616d116 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -66,6 +66,7 @@ enum class readline_cmd_t { backward_jump_till, func_and, expand_abbr, + delete_or_exit, cancel, repeat_jump, // NOTE: This one has to be last. diff --git a/src/reader.cpp b/src/reader.cpp index cf23e944c..0baa5d1a9 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1010,6 +1010,7 @@ static bool command_ends_paging(readline_cmd_t c, bool focused_on_search_field) case rl::history_token_search_backward: case rl::history_token_search_forward: case rl::accept_autosuggestion: + case rl::delete_or_exit: case rl::cancel: { // These commands always end paging. return true; @@ -2456,6 +2457,17 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat reader_repaint_needed(); break; } + case rl::delete_or_exit: { + if (!command_line.text.empty()) { + command_line.position = 0; + command_line.text = L""; + update_buff_pos(&command_line, 0); + reader_repaint_needed(); + } else { + reader_set_end_loop(true); + } + break; + } case rl::cancel: { // The only thing we can cancel right now is paging, which we handled up above. break;