From 0d2c20bceb215ca90e7238f7d2ae0476592d19ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 9 Sep 2019 13:29:07 +0200 Subject: [PATCH] [apps/graph] Fix function renaming Scenario: Funciton renamed f123456 would be saved as f12345 due to buffer size problem --- .../list/text_field_function_title_cell.cpp | 1 + .../list/text_field_function_title_cell.h | 4 +-- ...text_field_with_max_length_and_extension.h | 28 +++++++++++++++++++ apps/shared/function.h | 2 +- escher/include/escher/text_field.h | 1 + 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 apps/graph/list/text_field_with_max_length_and_extension.h diff --git a/apps/graph/list/text_field_function_title_cell.cpp b/apps/graph/list/text_field_function_title_cell.cpp index d33b6f821..ecd7a7567 100644 --- a/apps/graph/list/text_field_function_title_cell.cpp +++ b/apps/graph/list/text_field_function_title_cell.cpp @@ -30,6 +30,7 @@ void TextFieldFunctionTitleCell::setEditing(bool editing) { m_textField.setExtensionLength(extensionLength); m_textField.setEditing(true); m_textField.setText(previousText); + m_textField.setDraftTextBufferSize(Poincare::SymbolAbstract::k_maxNameSize+extensionLength); } bool TextFieldFunctionTitleCell::isEditing() const { diff --git a/apps/graph/list/text_field_function_title_cell.h b/apps/graph/list/text_field_function_title_cell.h index c9a113b22..0d2b95d9b 100644 --- a/apps/graph/list/text_field_function_title_cell.h +++ b/apps/graph/list/text_field_function_title_cell.h @@ -3,7 +3,7 @@ #include #include -#include +#include "text_field_with_max_length_and_extension.h" namespace Graph { @@ -42,7 +42,7 @@ private: constexpr static KDCoordinate k_textFieldRightMargin = 4; constexpr static int k_textFieldBufferSize = Shared::Function::k_maxNameWithArgumentSize; float verticalAlignmentGivenExpressionBaselineAndRowHeight(KDCoordinate expressionBaseline, KDCoordinate rowHeight) const override; - Shared::TextFieldWithExtension m_textField; + TextFieldWithMaxLengthAndExtension m_textField; char m_textFieldBuffer[k_textFieldBufferSize]; }; diff --git a/apps/graph/list/text_field_with_max_length_and_extension.h b/apps/graph/list/text_field_with_max_length_and_extension.h new file mode 100644 index 000000000..b14740788 --- /dev/null +++ b/apps/graph/list/text_field_with_max_length_and_extension.h @@ -0,0 +1,28 @@ +#ifndef GRAPH_TEXT_FIELD_WITH_MAX_LENGTH_AND_EXTENSION_H +#define GRAPH_TEXT_FIELD_WITH_MAX_LENGTH_AND_EXTENSION_H + +#include + +namespace Graph { + +class TextFieldWithMaxLengthAndExtension : public Shared::TextFieldWithExtension { +public: + TextFieldWithMaxLengthAndExtension(size_t extensionLength, + Responder * parentResponder, + char * textBuffer, + size_t textBufferSize, + size_t draftTextBufferSize, + ::InputEventHandlerDelegate * inputEventHandlerDelegate, + ::TextFieldDelegate * delegate = nullptr, + const KDFont * size = KDFont::LargeFont, + float horizontalAlignment = 0.0f, + float verticalAlignment = 0.5f, + KDColor textColor = KDColorBlack, + KDColor backgroundColor = KDColorWhite) : + TextFieldWithExtension(extensionLength, parentResponder, textBuffer, textBufferSize, draftTextBufferSize, inputEventHandlerDelegate, delegate, size, horizontalAlignment, verticalAlignment, textColor, backgroundColor) {} + void setDraftTextBufferSize(size_t size) { m_contentView.setDraftTextBufferSize(size); } +}; + +} + +#endif diff --git a/apps/shared/function.h b/apps/shared/function.h index 863502b78..4e1094763 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -25,7 +25,7 @@ public: 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)" */; + constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedThetaArgumentByteLength; /* Function name and null-terminating char + "(θ)" */; static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr); // Constructors diff --git a/escher/include/escher/text_field.h b/escher/include/escher/text_field.h index c58e609ff..2c6e97211 100644 --- a/escher/include/escher/text_field.h +++ b/escher/include/escher/text_field.h @@ -55,6 +55,7 @@ protected: void setAlignment(float horizontalAlignment, float verticalAlignment); void setEditing(bool isEditing); void reinitDraftTextBuffer(); + void setDraftTextBufferSize(size_t size) { m_draftTextBufferSize = size; } /* If the text to be appended is too long to be added without overflowing the * buffer, nothing is done (not even adding few letters from the text to reach * the maximum buffer capacity) and false is returned. */