diff --git a/apps/calculation/app.cpp b/apps/calculation/app.cpp index 08d23b4bb..077fcc75d 100644 --- a/apps/calculation/app.cpp +++ b/apps/calculation/app.cpp @@ -27,6 +27,8 @@ App * App::Snapshot::unpack(Container * container) { void App::Snapshot::reset() { m_calculationStore.deleteAll(); + m_cacheBuffer[0] = 0; + m_cacheBufferInformation = 0; } App::Descriptor * App::Snapshot::descriptor() { @@ -41,7 +43,7 @@ App::Snapshot::Snapshot() : m_calculationStore(m_calculationBuffer, k_calculatio App::App(Snapshot * snapshot) : ExpressionFieldDelegateApp(snapshot, &m_editExpressionController), m_historyController(&m_editExpressionController, snapshot->calculationStore()), - m_editExpressionController(&m_modalViewController, this, &m_historyController, snapshot->calculationStore()) + m_editExpressionController(&m_modalViewController, this, snapshot->cacheBuffer(), snapshot->cacheBufferInformationAddress(), &m_historyController, snapshot->calculationStore()) { } diff --git a/apps/calculation/app.h b/apps/calculation/app.h index 6914c82df..eaa0040fa 100644 --- a/apps/calculation/app.h +++ b/apps/calculation/app.h @@ -24,11 +24,15 @@ public: void reset() override; Descriptor * descriptor() override; CalculationStore * calculationStore() { return &m_calculationStore; } + char * cacheBuffer() { return m_cacheBuffer; } + size_t * cacheBufferInformationAddress() { return &m_cacheBufferInformation; } private: CalculationStore m_calculationStore; // Set the size of the buffer needed to store the calculations static constexpr int k_calculationBufferSize = 10 * (sizeof(Calculation) + Calculation::k_numberOfExpressions * Constant::MaxSerializedExpressionSize + sizeof(Calculation *)); char m_calculationBuffer[k_calculationBufferSize]; + char m_cacheBuffer[EditExpressionController::k_cacheBufferSize]; + size_t m_cacheBufferInformation; }; static App * app() { return static_cast(Container::activeApp()); diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index 2ae7929a9..060042c6e 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -38,13 +38,14 @@ void EditExpressionController::ContentView::reload() { markRectAsDirty(bounds()); } -EditExpressionController::EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, HistoryController * historyController, CalculationStore * calculationStore) : +EditExpressionController::EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, char * cacheBuffer, size_t * cacheBufferInformation, HistoryController * historyController, CalculationStore * calculationStore) : ViewController(parentResponder), + m_cacheBuffer(cacheBuffer), + m_cacheBufferInformation(cacheBufferInformation), m_historyController(historyController), m_calculationStore(calculationStore), m_contentView(this, static_cast(m_historyController->view()), inputEventHandlerDelegate, this, this) { - m_cacheBuffer[0] = 0; } void EditExpressionController::insertTextBody(const char * text) { diff --git a/apps/calculation/edit_expression_controller.h b/apps/calculation/edit_expression_controller.h index 1605f8b8d..cea45b339 100644 --- a/apps/calculation/edit_expression_controller.h +++ b/apps/calculation/edit_expression_controller.h @@ -14,7 +14,17 @@ namespace Calculation { /* TODO: implement a split view */ class EditExpressionController : public ViewController, public Shared::TextFieldDelegate, public Shared::LayoutFieldDelegate { public: - EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, HistoryController * historyController, CalculationStore * calculationStore); + EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, char * cacheBuffer, size_t * cacheBufferInformation, HistoryController * historyController, CalculationStore * calculationStore); + + /* k_layoutBufferMaxSize dictates the size under which the expression being + * edited can be remembered when the user leaves Calculation. */ + static constexpr int k_layoutBufferMaxSize = 1024; + /* k_cacheBufferSize is the size of the array to which m_cacheBuffer points. + * It is used both as a way to buffer expression when pushing them the + * CalculationStore, and as a storage for the current input when leaving the + * application. */ + static constexpr int k_cacheBufferSize = (k_layoutBufferMaxSize < Constant::MaxSerializedExpressionSize) ? Constant::MaxSerializedExpressionSize : k_layoutBufferMaxSize; + View * view() override { return &m_contentView; } void didBecomeFirstResponder() override; void viewWillAppear() override; @@ -49,8 +59,8 @@ private: bool inputViewDidReceiveEvent(Ion::Events::Event event, bool shouldDuplicateLastCalculation); bool inputViewDidFinishEditing(const char * text, Poincare::Layout layoutR); bool inputViewDidAbortEditing(const char * text); - static constexpr int k_cacheBufferSize = Constant::MaxSerializedExpressionSize; - char m_cacheBuffer[k_cacheBufferSize]; + char * m_cacheBuffer; + size_t * m_cacheBufferInformation; HistoryController * m_historyController; CalculationStore * m_calculationStore; ContentView m_contentView;