Pull char_input_style_t into a top-level enum

Review feedback from
https://github.com/fish-shell/fish-shell/pull/6713#pullrequestreview-369853776
This commit is contained in:
ridiculousfish 2020-03-07 13:55:19 -08:00
parent 0ccedfbd09
commit f851bb709b
3 changed files with 16 additions and 14 deletions

View file

@ -510,8 +510,8 @@ char_event_t inputter_t::readch(bool allow_commands) {
// Hackish: mark the input style. // Hackish: mark the input style.
res.input_style = evt.get_readline() == readline_cmd_t::self_insert_notfirst res.input_style = evt.get_readline() == readline_cmd_t::self_insert_notfirst
? char_event_t::style_notfirst ? char_input_style_t::notfirst
: char_event_t::style_normal; : char_input_style_t::normal;
return res; return res;
} }
case readline_cmd_t::func_and: { case readline_cmd_t::func_and: {

View file

@ -97,6 +97,16 @@ enum class char_event_type_t : uint8_t {
check_exit, 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 { class char_event_t {
union { union {
/// Set if the type is charc. /// Set if the type is charc.
@ -110,16 +120,8 @@ class char_event_t {
/// The type of event. /// The type of event.
char_event_type_t type; char_event_type_t type;
/// Hackish: the input style, which describes how char events (only) are applied to the command /// The style to use when inserting characters into the command line.
/// line. Note this is set only after applying bindings; it is not set from readb(). char_input_style_t input_style{char_input_style_t::normal};
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 sequence of characters in the input mapping which generated this event. /// 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. /// Note that the generic self-insert case does not have any characters, so this would be empty.

View file

@ -2400,7 +2400,7 @@ maybe_t<char_event_t> reader_data_t::read_normal_chars(readline_loop_state_t &rl
if (!event_is_normal_char(evt) || !can_read(STDIN_FILENO)) { if (!event_is_normal_char(evt) || !can_read(STDIN_FILENO)) {
event_needing_handling = std::move(evt); event_needing_handling = std::move(evt);
break; 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) { active_edit_line()->position == 0) {
// The cursor is at the beginning and nothing is accumulated, so skip this character. // The cursor is at the beginning and nothing is accumulated, so skip this character.
continue; continue;
@ -3287,7 +3287,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars_or_0) {
} else { } else {
// Ordinary char. // Ordinary char.
wchar_t c = event_needing_handling->get_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) { active_edit_line()->position == 0) {
// This character is skipped. // This character is skipped.
} else if (!fish_reserved_codepoint(c) && (c >= L' ' || c == L'\n' || c == L'\r') && } else if (!fish_reserved_codepoint(c) && (c >= L' ' || c == L'\n' || c == L'\r') &&