From da8286d3f7ac2a04a7a4dcc5fa8f1f4280a97ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 22 May 2018 15:39:21 +0200 Subject: [PATCH] [code] Escaping the input loop on a 'home' event should be handled by the code app instead of the console controller to ensure to escape the input loop even when the toolbox (or any modal) is displayed --- apps/code/app.cpp | 13 +++++++++++++ apps/code/app.h | 1 + apps/code/console_controller.cpp | 2 +- apps/code/console_controller.h | 4 ++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/code/app.cpp b/apps/code/app.cpp index 7f362d515..9e1d94429 100644 --- a/apps/code/app.cpp +++ b/apps/code/app.cpp @@ -87,6 +87,19 @@ App::App(Container * container, Snapshot * snapshot) : { } +bool App::handleEvent(Ion::Events::Event event) { + if (event == Ion::Events::Home && m_consoleController.inputRunLoopActive()) { + // We need to return true here because we want to actually exit from the + // input run loop, which requires ending a dispatchEvent cycle. + m_consoleController.askInputRunLoopTermination(); + if (m_modalViewController.isDisplayingModal()) { + m_modalViewController.dismissModalViewController(); + } + return true; + } + return false; +} + bool App::textInputDidReceiveEvent(TextInput * textInput, Ion::Events::Event event) { const char * pythonText = Helpers::PythonTextForEvent(event); if (pythonText != nullptr) { diff --git a/apps/code/app.h b/apps/code/app.h index 9b97f040d..68a7a826d 100644 --- a/apps/code/app.h +++ b/apps/code/app.h @@ -39,6 +39,7 @@ public: StackViewController * stackViewController() { return &m_codeStackViewController; } ConsoleController * consoleController() { return &m_consoleController; } PythonToolbox * pythonToolbox() { return &m_toolbox; } + bool handleEvent(Ion::Events::Event event) override; bool textInputDidReceiveEvent(TextInput * textInput, Ion::Events::Event event); private: App(Container * container, Snapshot * snapshot); diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index 9f0e4ee96..0bc922854 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -133,7 +133,7 @@ void ConsoleController::didBecomeFirstResponder() { } bool ConsoleController::handleEvent(Ion::Events::Event event) { - if ((event == Ion::Events::Home || event == Ion::Events::Up) && inputRunLoopActive()) { + if (event == Ion::Events::Up && inputRunLoopActive()) { askInputRunLoopTermination(); // We need to return true here because we want to actually exit from the // input run loop, which requires ending a dispatchEvent cycle. diff --git a/apps/code/console_controller.h b/apps/code/console_controller.h index 1bdcc00d7..0ec6bd690 100644 --- a/apps/code/console_controller.h +++ b/apps/code/console_controller.h @@ -34,6 +34,8 @@ public: void autoImport(); void autoImportScript(Script script, bool force = false); void runAndPrintForCommand(const char * command); + bool inputRunLoopActive() { return m_inputRunLoopActive; } + void askInputRunLoopTermination() { m_inputRunLoopActive = false; } // ViewController View * view() override { return &m_selectableTableView; } @@ -76,8 +78,6 @@ private: static constexpr const char * k_importCommand1 = "from "; static constexpr const char * k_importCommand2 = " import *"; static constexpr size_t k_maxImportCommandSize = 5 + 9 + TextField::maxBufferSize(); // strlen(k_importCommand1) + strlen(k_importCommand2) + TextField::maxBufferSize() - bool inputRunLoopActive() { return m_inputRunLoopActive; } - void askInputRunLoopTermination() { m_inputRunLoopActive = false; } static constexpr int LineCellType = 0; static constexpr int EditCellType = 1; static constexpr int k_numberOfLineCells = 15; // May change depending on the screen height