From cce6591f54f29f6c4997a13a6138925bd5712762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 6 Nov 2018 10:49:57 +0100 Subject: [PATCH] [apps] When editing an expression model, replace UnknownX with 'x' --- .../storage_expression_model_list_controller.cpp | 10 +++++++++- poincare/include/poincare/symbol.h | 1 + poincare/src/symbol.cpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/shared/storage_expression_model_list_controller.cpp b/apps/shared/storage_expression_model_list_controller.cpp index 9366f0f58..020f5ac43 100644 --- a/apps/shared/storage_expression_model_list_controller.cpp +++ b/apps/shared/storage_expression_model_list_controller.cpp @@ -1,4 +1,5 @@ #include "storage_expression_model_list_controller.h" +#include namespace Shared { @@ -183,9 +184,16 @@ void StorageExpressionModelListController::editExpression(Ion::Events::Event eve char initialTextContent[TextField::maxBufferSize()]; if (event == Ion::Events::OK || event == Ion::Events::EXE) { Ion::Storage::Record record = modelStore()->recordAtIndex(modelIndexForRow(selectedRow())); - ExpiringPointer model = modelStore()->modelForRecord(record); + ExpiringPointer model = modelStore()->modelForRecord(record); model->text(initialTextContent, TextField::maxBufferSize()); initialText = initialTextContent; + // Replace Poincare::Symbol::SpecialSymbols::UnknownX with 'x' + size_t initialTextLength = strlen(initialText); + for (size_t i = 0; i < initialTextLength; i++) { + if (initialTextContent[i] == Poincare::Symbol::SpecialSymbols::UnknownX) { + initialTextContent[i] = Poincare::Symbol::k_unknownXReadableChar; + } + } } inputController()->edit(this, event, this, initialText, [](void * context, void * sender){ diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 07f7389ae..77b1eff52 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -48,6 +48,7 @@ class Symbol final : public SymbolAbstract { friend class Store; public: static constexpr char k_ans[] = "ans"; + static constexpr char k_unknownXReadableChar = 'x'; enum SpecialSymbols : char { /* We can use characters from 1 to 31 as they do not correspond to usual * characters but events as 'end of text', 'backspace'... */ diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 9a6e74913..19c340e6e 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -75,7 +75,7 @@ float SymbolNode::characteristicXRange(Context & context, Preferences::AngleUnit Layout SymbolNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { if (m_name[0] == Symbol::SpecialSymbols::UnknownX) { assert(m_name[1] == 0); - return CharLayout('x'); + return CharLayout(Symbol::k_unknownXReadableChar); } if (strcmp(m_name, "u(n)") == 0) { return HorizontalLayout(