From aa1d1165e8324003d07b1fc8099446564d0d4c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 5 Sep 2019 09:34:01 +0200 Subject: [PATCH] =?UTF-8?q?[apps/graph]=20Fix=20function=20name=20edition:?= =?UTF-8?q?=20the=20cursor=20is=20positioned=20right=20after=20the=20'('?= =?UTF-8?q?=20(bug=20due=20to=20the=20fact=20that=20=CE=B8=20takes=202=20b?= =?UTF-8?q?ytes)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/graph/list/list_controller.cpp | 3 ++- apps/graph/list/text_field_function_title_cell.cpp | 8 +++----- apps/graph/list/text_field_function_title_cell.h | 1 - apps/shared/function.h | 6 ++++-- apps/shared/function_list_controller.cpp | 4 ++-- apps/shared/text_field_with_extension.h | 1 + 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 0dbde54b4..0072ff370 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -49,7 +49,8 @@ bool ListController::textFieldDidFinishEditing(TextField * textField, const char assert(textField != nullptr); // Compute the new name size_t textLength = strlen(text); - size_t argumentLength = Function::k_parenthesedArgumentLength; + bool textIncludesTheta = UTF8Helper::CodePointSearch(text, UCodePointGreekSmallLetterTheta) != nullptr; + size_t argumentLength = textIncludesTheta ? Function::k_parenthesedThetaArgumentByteLength : Function::k_parenthesedXNTArgumentByteLength; constexpr int maxBaseNameSize = Function::k_maxNameWithArgumentSize; char baseName[maxBaseNameSize]; if (textLength <= argumentLength) { diff --git a/apps/graph/list/text_field_function_title_cell.cpp b/apps/graph/list/text_field_function_title_cell.cpp index 89b1aec01..4a94c0a4e 100644 --- a/apps/graph/list/text_field_function_title_cell.cpp +++ b/apps/graph/list/text_field_function_title_cell.cpp @@ -10,7 +10,7 @@ static inline float maxFloat(float x, float y) { return x > y ? x : y; } TextFieldFunctionTitleCell::TextFieldFunctionTitleCell(ListController * listController, Orientation orientation, const KDFont * font) : Shared::FunctionTitleCell(orientation), Responder(listController), - m_textField(Shared::Function::k_parenthesedArgumentLength, this, m_textFieldBuffer, k_textFieldBufferSize, k_textFieldBufferSize, nullptr, listController, font, 1.0f, 0.5f) + m_textField(Shared::Function::k_parenthesedThetaArgumentByteLength, this, m_textFieldBuffer, k_textFieldBufferSize, k_textFieldBufferSize, nullptr, listController, font, 1.0f, 0.5f) { } @@ -26,6 +26,8 @@ Responder * TextFieldFunctionTitleCell::responder() { void TextFieldFunctionTitleCell::setEditing(bool editing) { Container::activeApp()->setFirstResponder(&m_textField); const char * previousText = m_textField.text(); + bool titleIncludesTheta = *(UTF8Helper::CodePointSearch(previousText, UCodePointGreekSmallLetterTheta)) != 0; + m_textField.setExtensionLength(titleIncludesTheta ? Shared::Function::k_parenthesedThetaArgumentByteLength : Shared::Function::k_parenthesedXNTArgumentByteLength); m_textField.setEditing(true); m_textField.setText(previousText); } @@ -44,10 +46,6 @@ void TextFieldFunctionTitleCell::setColor(KDColor color) { m_textField.setTextColor(color); } -void TextFieldFunctionTitleCell::setText(const char * title) { - m_textField.setText(title); -} - void TextFieldFunctionTitleCell::setHorizontalAlignment(float alignment) { assert(alignment >= 0.0f && alignment <= 1.0f); m_textField.setAlignment(alignment, verticalAlignment()); diff --git a/apps/graph/list/text_field_function_title_cell.h b/apps/graph/list/text_field_function_title_cell.h index 68b1cbf25..c9a113b22 100644 --- a/apps/graph/list/text_field_function_title_cell.h +++ b/apps/graph/list/text_field_function_title_cell.h @@ -15,7 +15,6 @@ public: TextField * textField() { return &m_textField; } void setEditing(bool editing); bool isEditing() const; - void setText(const char * textContent); void setHorizontalAlignment(float alignment); // FunctionTitleCell diff --git a/apps/shared/function.h b/apps/shared/function.h index 08cfcaade..87580961b 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -22,8 +22,10 @@ public: }; /* Possible arguments: n, x, t, θ * The CodePoint θ is two char long. */ - constexpr static int k_parenthesedArgumentLength = 4; - constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedArgumentLength; /* Function name and null-terminating char + "(x)" */; + constexpr static int k_parenthesedArgumentCodePointLength = 3; + constexpr static int k_parenthesedThetaArgumentByteLength = 4; + constexpr static int k_parenthesedXNTArgumentByteLength = 3; + constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedThetaArgumentByteLength; /* Function name and null-terminating char + "(x)" */; static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr); // Constructors diff --git a/apps/shared/function_list_controller.cpp b/apps/shared/function_list_controller.cpp index 1913a216e..e27acf0cb 100644 --- a/apps/shared/function_list_controller.cpp +++ b/apps/shared/function_list_controller.cpp @@ -237,7 +237,7 @@ void FunctionListController::configureFunction(Ion::Storage::Record record) { void FunctionListController::computeTitlesColumnWidth(bool forceMax) { if (forceMax) { - m_titlesColumnWidth = nameWidth(Function::k_maxNameWithArgumentSize - 1)+k_functionTitleSumOfMargins; + m_titlesColumnWidth = nameWidth(Poincare::SymbolAbstract::k_maxNameSize + Function::k_parenthesedArgumentCodePointLength - 1)+k_functionTitleSumOfMargins; return; } KDCoordinate maxTitleWidth = maxFunctionNameWidth()+k_functionTitleSumOfMargins; @@ -266,7 +266,7 @@ KDCoordinate FunctionListController::maxFunctionNameWidth() { assert(dotPosition != nullptr); maxNameLength = maxInt(maxNameLength, dotPosition-functionName); } - return nameWidth(maxNameLength + Function::k_parenthesedArgumentLength); + return nameWidth(maxNameLength + Function::k_parenthesedArgumentCodePointLength); } void FunctionListController::didChangeModelsList() { diff --git a/apps/shared/text_field_with_extension.h b/apps/shared/text_field_with_extension.h index 106e6833f..688762ade 100644 --- a/apps/shared/text_field_with_extension.h +++ b/apps/shared/text_field_with_extension.h @@ -22,6 +22,7 @@ public: TextField(parentResponder, textBuffer, textBufferSize, draftTextBufferSize, inputEventHandlerDelegate, delegate, size, horizontalAlignment, verticalAlignment, textColor, backgroundColor), m_extensionLength(extensionLength) {} + void setExtensionLength(size_t extensionLength) { m_extensionLength = extensionLength; } private: void willSetCursorLocation(const char * * location) override; bool privateRemoveEndOfLine() override;