From ad8e7849383cf2b72d0470de62716746afebaf18 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 7 Jul 2020 12:32:37 -0400 Subject: [PATCH] LibEdit: Make Ctrl-d on an empty line mean EOD again --- Libraries/LibLine/Editor.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index b6d1fee4ea..75d137695e 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -757,11 +757,22 @@ void Editor::handle_read_event() m_refresh_needed = true; continue; } + // Normally ^D. `stty eof \^n` can change it to ^N (or something else), but Serenity doesn't have `stty` yet. + // Handle it before ctrl shortcuts below and only continue if the buffer is empty, so that the editing shortcuts can take effect else. + if (codepoint == m_termios.c_cc[VEOF] && m_buffer.is_empty()) { + printf("\n"); + if (!m_always_refresh) { + m_input_error = Error::Eof; + finish(); + } + continue; + } // ^A if (codepoint == ctrl('A')) { m_cursor = 0; continue; } + // ^B if (codepoint == ctrl('B')) { do_cursor_left(Character); continue; @@ -910,18 +921,6 @@ void Editor::handle_read_event() } continue; } - // Normally ^D - if (codepoint == m_termios.c_cc[VEOF]) { - if (m_buffer.is_empty()) { - printf("\n"); - if (!m_always_refresh) { - m_input_error = Error::Eof; - finish(); - continue; - } - } - continue; - } if (codepoint == '\n') { finish(); continue;