From 879843ce2baa3d4302fbd9105c515cbb2bb8b7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 3 Feb 2020 14:34:53 +0100 Subject: [PATCH] [escher] LayoutField: reset selection when the field should finish editing This fixes the following bug: in solver, input Matrix(Matrix()) and select the inner Matrix. When handling "OK" event, the "=0" is inserted at a wrong position leading to a crash ! --- escher/include/escher/layout_field.h | 4 +--- escher/src/layout_field.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/escher/include/escher/layout_field.h b/escher/include/escher/layout_field.h index 518b849b9..5826ad7b3 100644 --- a/escher/include/escher/layout_field.h +++ b/escher/include/escher/layout_field.h @@ -41,9 +41,7 @@ public: /* Responder */ bool handleEventWithText(const char * text, bool indentation = false, bool forceCursorRightOfText = false) override; bool handleEvent(Ion::Events::Event event) override; - bool shouldFinishEditing(Ion::Events::Event event) override { // TODO REMOVE ? - return m_delegate->layoutFieldShouldFinishEditing(this, event); - } + bool shouldFinishEditing(Ion::Events::Event event) override; // TODO REMOVE ? // Selection bool resetSelection() { return m_contentView.resetSelection(); } diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index df513c08c..98d07fca9 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -369,6 +369,14 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool return true; } +bool LayoutField::shouldFinishEditing(Ion::Events::Event event) { + if (m_delegate->layoutFieldShouldFinishEditing(this, event)) { + resetSelection(); + return true; + } + return false; +} + bool LayoutField::handleEvent(Ion::Events::Event event) { bool didHandleEvent = false; KDSize previousSize = minimalSizeForOptimalDisplay();