Skip to content

Commit f6afb70

Browse files
alimpfardawesomekling
authored andcommitted
LibLine: Handle read events serially
Previously LibLine accepted read callbacks while it was in the process of reading input, this wasn't an issue as no async code was being executed up until the Shell autocompletion came along. Simply defer input processing while processing input to avoid causing problems. Fixes #13280.
1 parent 5e541aa commit f6afb70

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Userland/Libraries/LibLine/Editor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,13 @@ void Editor::handle_interrupt_event()
791791

792792
void Editor::handle_read_event()
793793
{
794+
if (m_prohibit_input_processing) {
795+
m_have_unprocessed_read_event = true;
796+
return;
797+
}
798+
799+
auto prohibit_scope = prohibit_input();
800+
794801
char keybuf[16];
795802
ssize_t nread = 0;
796803

Userland/Libraries/LibLine/Editor.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ class Editor : public Core::Object {
241241

242242
const Utf32View buffer_view() const { return { m_buffer.data(), m_buffer.size() }; }
243243

244+
auto prohibit_input()
245+
{
246+
auto previous_value = m_prohibit_input_processing;
247+
m_prohibit_input_processing = true;
248+
m_have_unprocessed_read_event = false;
249+
return ScopeGuard {
250+
[this, previous_value] {
251+
m_prohibit_input_processing = previous_value;
252+
if (!m_prohibit_input_processing && m_have_unprocessed_read_event)
253+
handle_read_event();
254+
}
255+
};
256+
}
257+
244258
private:
245259
explicit Editor(Configuration configuration = Configuration::from_config());
246260

@@ -500,6 +514,8 @@ class Editor : public Core::Object {
500514
Vector<int, 2> m_signal_handlers;
501515

502516
bool m_is_editing { false };
517+
bool m_prohibit_input_processing { false };
518+
bool m_have_unprocessed_read_event { false };
503519

504520
Configuration m_configuration;
505521
};

0 commit comments

Comments
 (0)