Implement self-insert-notfirst in reader

This adds basic support for self-insert-notfirst. When we see a
self-insert-nonempty char event, we kick it back to the outer loop,
which only inserts the character if the cursor is not at the beginning.
This commit is contained in:
ridiculousfish 2020-03-04 14:26:04 -08:00
parent 2e4cb15880
commit b8a7cdacb6

View File

@ -2525,6 +2525,8 @@ static bool text_ends_in_comment(const wcstring &text) {
/// \return true if an event is a normal character that should be inserted into the buffer.
static bool event_is_normal_char(const char_event_t &evt) {
if (!evt.is_char()) return false;
// Non-normal insertion styles are treated as a non-normal character.
if (evt.input_style != char_event_t::style_normal) return false;
auto c = evt.get_char();
return !fish_reserved_codepoint(c) && c > 31 && c != 127;
}
@ -3492,7 +3494,10 @@ maybe_t<wcstring> reader_data_t::readline(int nchars_or_0) {
} else {
// Ordinary char.
wchar_t c = event_needing_handling->get_char();
if (!fish_reserved_codepoint(c) && (c >= L' ' || c == L'\n' || c == L'\r') &&
if (event_needing_handling->input_style == char_event_t::style_notfirst &&
active_edit_line()->position() == 0) {
// This character is skipped.
} else if (!fish_reserved_codepoint(c) && (c >= L' ' || c == L'\n' || c == L'\r') &&
c != 0x7F) {
// Regular character.
editable_line_t *el = active_edit_line();