mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[escher] TextField: when handling event with text, replace system
parenthesis by user parenthesis to switch from layout structure to linear text. When copying a layout and pasting it to a textfield, we add required parentheses: 2+1 ----- serializes to ---> [2+1]/3 and is turned to (2+1)/3 before being 3 handled by a textfield.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <escher/clipboard.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <assert.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace Poincare {
|
||||
*/
|
||||
|
||||
namespace SerializationHelper {
|
||||
|
||||
void ReplaceSystemParenthesesByUserParentheses(char * buffer);
|
||||
|
||||
// SerializableReference to text
|
||||
int Infix(
|
||||
const TreeNode * node,
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user