diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 13232f5a4..0fb8c03d0 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include static inline int minInt(int x, int y) { return x < y ? x : y; } @@ -462,6 +463,9 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo char buffer[bufferSize]; UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, eventText, UCodePointEmpty); + // Replace System parentheses (used to keep layout tree structure) by normal parentheses + Poincare::SerializationHelper::ReplaceSystemParenthesesByUserParentheses(buffer); + const char * nextCursorLocation = m_contentView.draftTextBuffer() + draftTextLength(); if (insertTextAtLocation(buffer, cursorLocation())) { /* The cursor position depends on the text as we sometimes want to position diff --git a/poincare/include/poincare/serialization_helper.h b/poincare/include/poincare/serialization_helper.h index 4ee86219b..3496687c0 100644 --- a/poincare/include/poincare/serialization_helper.h +++ b/poincare/include/poincare/serialization_helper.h @@ -13,6 +13,9 @@ namespace Poincare { */ namespace SerializationHelper { + + void ReplaceSystemParenthesesByUserParentheses(char * buffer); + // SerializableReference to text int Infix( const TreeNode * node, diff --git a/poincare/src/serialization_helper.cpp b/poincare/src/serialization_helper.cpp index 4991226e4..c2d1566d1 100644 --- a/poincare/src/serialization_helper.cpp +++ b/poincare/src/serialization_helper.cpp @@ -1,10 +1,30 @@ #include #include +#include #include #include namespace Poincare { +void replaceOneCharSizedCodePointWith(char * buffer, CodePoint searchedCodePoint, CodePoint newCodePoint) { + assert(UTF8Decoder::CharSizeOfCodePoint(searchedCodePoint == 1)); + assert(UTF8Decoder::CharSizeOfCodePoint(newCodePoint == 1)); + UTF8Helper::PerformAtCodePoints( + buffer, + searchedCodePoint, + [](int codePointOffset, void * text, int newCodePoint, int bufferLength) { + *((char *)text+codePointOffset) = (char)newCodePoint; + }, + [](int c1, void * c2, int c3, int c4) {}, + (void *)buffer, + newCodePoint); +} + +void SerializationHelper::ReplaceSystemParenthesesByUserParentheses(char * buffer) { + replaceOneCharSizedCodePointWith(buffer, UCodePointLeftSystemParenthesis, '('); + replaceOneCharSizedCodePointWith(buffer, UCodePointRightSystemParenthesis, ')'); +} + static bool checkBufferSize(char * buffer, int bufferSize, int * result) { // If buffer has size 0 or 1, put a zero if it fits and return if (bufferSize == 0) {