[apps/graph] Fix function name edition: the cursor is positioned right

after the '(' (bug due to the fact that θ takes 2 bytes)
This commit is contained in:
Émilie Feral
2019-09-05 09:34:01 +02:00
parent f70fb98a23
commit aa1d1165e8
6 changed files with 12 additions and 11 deletions

View File

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

View File

@@ -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());

View File

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

View File

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

View File

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

View File

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