diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 8a7b4e08..674276f7 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -295,10 +295,14 @@ ScreenInteractive ScreenInteractive::FitComponent() { } void ScreenInteractive::Post(Task task) { - if (!quit_) { - task_sender_->Send(std::move(task)); - } + // Task/Events sent toward inactive screen or screen waiting to become + // inactive are dropped. + if (!task_sender_) + return; + + task_sender_->Send(std::move(task)); } + void ScreenInteractive::PostEvent(Event event) { Post(event); } diff --git a/src/ftxui/component/screen_interactive_test.cpp b/src/ftxui/component/screen_interactive_test.cpp index 9592d932..957e98b1 100644 --- a/src/ftxui/component/screen_interactive_test.cpp +++ b/src/ftxui/component/screen_interactive_test.cpp @@ -47,6 +47,20 @@ TEST(ScreenInteractive, Signal_SIGFPE) { TestSignal(SIGFPE); } +// Regression test for: +// https://github.com/ArthurSonzogni/FTXUI/issues/402 +TEST(ScreenInteractive, PostEventToNonActive) { + auto screen = ScreenInteractive::FitComponent(); + screen.Post(Event::Custom); +} + +// Regression test for: +// https://github.com/ArthurSonzogni/FTXUI/issues/402 +TEST(ScreenInteractive, PostTaskToNonActive) { + auto screen = ScreenInteractive::FitComponent(); + screen.Post([] {}); +} + } // namespace ftxui // Copyright 2021 Arthur Sonzogni. All rights reserved.