[apps/graph] Fix function renaming

Scenario: Funciton renamed f123456 would be saved as f12345 due to
buffer size problem
This commit is contained in:
Léa Saviot
2019-09-09 13:29:07 +02:00
parent d9f650d283
commit 0d2c20bceb
5 changed files with 33 additions and 3 deletions

View File

@@ -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 {

View File

@@ -3,7 +3,7 @@
#include <apps/shared/function_title_cell.h>
#include <apps/shared/function.h>
#include <apps/shared/text_field_with_extension.h>
#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];
};

View File

@@ -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 <apps/shared/text_field_with_extension.h>
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

View File

@@ -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

View File

@@ -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. */