From f851bb709b025ae2117a52850f2b28b83b49897c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 7 Mar 2020 13:55:19 -0800 Subject: [PATCH] Pull char_input_style_t into a top-level enum Review feedback from https://github.com/fish-shell/fish-shell/pull/6713#pullrequestreview-369853776 --- src/input.cpp | 4 ++-- src/input_common.h | 22 ++++++++++++---------- src/reader.cpp | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index f175046ef..205d40655 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -510,8 +510,8 @@ char_event_t inputter_t::readch(bool allow_commands) { // Hackish: mark the input style. res.input_style = evt.get_readline() == readline_cmd_t::self_insert_notfirst - ? char_event_t::style_notfirst - : char_event_t::style_normal; + ? char_input_style_t::notfirst + : char_input_style_t::normal; return res; } case readline_cmd_t::func_and: { diff --git a/src/input_common.h b/src/input_common.h index 7053309ae..380c988a4 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -97,6 +97,16 @@ enum class char_event_type_t : uint8_t { check_exit, }; +/// Hackish: the input style, which describes how char events (only) are applied to the command +/// line. Note this is set only after applying bindings; it is not set from readb(). +enum class char_input_style_t : uint8_t { + // Insert characters normally. + normal, + + // Insert characters only if the cursor is not at the beginning. Otherwise, discard them. + notfirst, +}; + class char_event_t { union { /// Set if the type is charc. @@ -110,16 +120,8 @@ class char_event_t { /// The type of event. char_event_type_t type; - /// Hackish: the input style, which describes how char events (only) are applied to the command - /// line. Note this is set only after applying bindings; it is not set from readb(). - enum input_style_t : uint8_t { - // Insert characters normally. - style_normal, - - // Insert characters only if the cursor is not at the beginning. Otherwise, discard them. - style_notfirst, - }; - input_style_t input_style{style_normal}; + /// The style to use when inserting characters into the command line. + char_input_style_t input_style{char_input_style_t::normal}; /// The sequence of characters in the input mapping which generated this event. /// Note that the generic self-insert case does not have any characters, so this would be empty. diff --git a/src/reader.cpp b/src/reader.cpp index 0bd7dacee..6b7ac8e9e 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2400,7 +2400,7 @@ maybe_t reader_data_t::read_normal_chars(readline_loop_state_t &rl if (!event_is_normal_char(evt) || !can_read(STDIN_FILENO)) { event_needing_handling = std::move(evt); break; - } else if (evt.input_style == char_event_t::style_notfirst && accumulated_chars.empty() && + } else if (evt.input_style == char_input_style_t::notfirst && accumulated_chars.empty() && active_edit_line()->position == 0) { // The cursor is at the beginning and nothing is accumulated, so skip this character. continue; @@ -3287,7 +3287,7 @@ maybe_t reader_data_t::readline(int nchars_or_0) { } else { // Ordinary char. wchar_t c = event_needing_handling->get_char(); - if (event_needing_handling->input_style == char_event_t::style_notfirst && + if (event_needing_handling->input_style == char_input_style_t::notfirst && active_edit_line()->position == 0) { // This character is skipped. } else if (!fish_reserved_codepoint(c) && (c >= L' ' || c == L'\n' || c == L'\r') &&