From 0ffcf34eb71a48978d3ea19004a2ad71f6cfe7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 3 Feb 2020 11:02:34 +0100 Subject: [PATCH] [escher] TextField: make the handleEventWithText behaviour consistent: when a text cannot be inserted because it overflows the buffer, don't add anything insertTextAtLocation already behaves like this but handleEventWithText used to cap the inserted text which sometimes leads to a different behaviour - it would insert a truncated text --- escher/src/text_field.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index ccbdfc5e5..2c43e9bcb 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -492,7 +492,13 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo char buffer[bufferSize]; { CodePoint c[] = {UCodePointEmpty, '\n'}; - UTF8Helper::CopyAndRemoveCodePoints(buffer, bufferSize, eventText, c, 2); + bool complete = UTF8Helper::CopyAndRemoveCodePoints(buffer, bufferSize, eventText, c, 2); + /* If the text is too long to be stored in buffer, we do not insert any + * text. This behaviour is consistent with 'insertTextAtLocation' + * behaviour. */ + if (!complete) { + return false; + } } // Replace System parentheses (used to keep layout tree structure) by normal parentheses Poincare::SerializationHelper::ReplaceSystemParenthesesByUserParentheses(buffer);