From 8f86769cd10e3df9e82add5e7796a97686ca2bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 10 Jan 2020 10:49:16 +0100 Subject: [PATCH] [escher/layout_field] When pasting, force cursor right of pasted text Even if the text is inserted code point per code point --- escher/src/layout_field.cpp | 2 +- poincare/include/poincare/layout_cursor.h | 2 +- poincare/src/layout_cursor.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 4fd1e875b..1550c0ff2 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -336,7 +336,7 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool if (resultExpression.isUninitialized()) { // The text is not parsable (for instance, ",") and is added char by char. KDSize previousLayoutSize = minimalSizeForOptimalDisplay(); - m_contentView.cursor()->insertText(text); + m_contentView.cursor()->insertText(text, forceCursorRightOfText); reload(previousLayoutSize); return true; } diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index 12fcfd3a0..33efc29c6 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -114,7 +114,7 @@ public: void addEmptyTenPowerLayout(); void addFractionLayoutAndCollapseSiblings(); void addXNTCodePointLayout(); - void insertText(const char * text); + void insertText(const char * text, bool forceCursorRightOfText = false); void addLayoutAndMoveCursor(Layout l); bool showEmptyLayoutIfNeeded() { return privateShowHideEmptyLayoutIfNeeded(true); } bool hideEmptyLayoutIfNeeded() { return privateShowHideEmptyLayoutIfNeeded(false); } diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index 548f2e0d4..05855430b 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -154,7 +154,7 @@ void LayoutCursor::addXNTCodePointLayout() { m_layout.addSibling(this, CodePointLayout::Builder(m_layout.XNTCodePoint()), true); } -void LayoutCursor::insertText(const char * text) { +void LayoutCursor::insertText(const char * text, bool forceCursorRightOfText) { Layout newChild; Layout pointedChild; UTF8Decoder decoder(text); @@ -199,7 +199,7 @@ void LayoutCursor::insertText(const char * text) { codePoint = decoder.nextCodePoint(); } } - if (!pointedChild.isUninitialized() && !pointedChild.parent().isUninitialized()) { + if (!forceCursorRightOfText && !pointedChild.isUninitialized() && !pointedChild.parent().isUninitialized()) { m_layout = pointedChild; m_position = Position::Right; }