From 03f07d65ed6197a4a6827d7ea41aae03eef055e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 19 Nov 2019 11:09:37 +0100 Subject: [PATCH] [escher/layout_field] Remove selection on simple left/right/up/down --- escher/include/escher/layout_field.h | 2 +- escher/src/layout_field.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/escher/include/escher/layout_field.h b/escher/include/escher/layout_field.h index 8532a6cd2..8008a47ec 100644 --- a/escher/include/escher/layout_field.h +++ b/escher/include/escher/layout_field.h @@ -44,7 +44,7 @@ public: } // Selection - void resetSelection() { m_contentView.resetSelection(); } + bool resetSelection() { return m_contentView.resetSelection(); } void deleteSelection(); private: diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 2dee5b5a9..3fb7d428f 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -376,7 +376,21 @@ bool LayoutField::privateHandleEvent(Ion::Events::Event event) { return false; } +static inline bool IsSimpleMoveEvent(Ion::Events::Event event) { + return event == Ion::Events::Left + || event == Ion::Events::Right + || event == Ion::Events::Up + || event == Ion::Events::Down; +} + bool LayoutField::privateHandleMoveEvent(Ion::Events::Event event, bool * shouldRecomputeLayout) { + if (!IsSimpleMoveEvent(event)) { + return false; + } + if (resetSelection()) { + *shouldRecomputeLayout = true; + return true; + } LayoutCursor result; if (event == Ion::Events::Left) { result = m_contentView.cursor()->cursorAtDirection(LayoutCursor::MoveDirection::Left, shouldRecomputeLayout); @@ -384,7 +398,8 @@ bool LayoutField::privateHandleMoveEvent(Ion::Events::Event event, bool * should result = m_contentView.cursor()->cursorAtDirection(LayoutCursor::MoveDirection::Right, shouldRecomputeLayout); } else if (event == Ion::Events::Up) { result = m_contentView.cursor()->cursorAtDirection(LayoutCursor::MoveDirection::Up, shouldRecomputeLayout); - } else if (event == Ion::Events::Down) { + } else { + assert(event == Ion::Events::Down); result = m_contentView.cursor()->cursorAtDirection(LayoutCursor::MoveDirection::Down, shouldRecomputeLayout); } if (result.isDefined()) {