[apps/sequence] Fix the insertion of sequence terms in text fields.

For instance, the serialization of the V_n layout is "v_{n}", which is
what we want to insert in an EditableExpressionView, but not in a Text
Field for which we want "v(n)".

Change-Id: Iab38058d982322891b530b3afd2d303a266643f9
This commit is contained in:
Léa Saviot
2018-01-19 17:31:37 +01:00
parent 64efb45c24
commit e29691e1f1
3 changed files with 49 additions and 19 deletions

View File

@@ -115,7 +115,26 @@ bool SequenceToolbox::selectAddedCell(int selectedRow){
int bufferSize = 10;
char buffer[bufferSize];
m_addedCellLayout[selectedRow]->writeTextInBuffer(buffer, bufferSize);
m_action(sender(), buffer);
if (m_action == MathToolbox::actionForTextField) {
// DIRTY. The symbols are layouted using a Subscript VerticalOffsetLayout,
// which serializes into "_{}", but we want parentheses for text fields. We
// thus need to remove any underscores, and changes brackets into
// parentheses.
for (int i = 0; i < bufferSize; i++) {
if (buffer[i] == '{') {
buffer[i] = '(';
}
if (buffer[i] == '}') {
buffer[i] = ')';
}
if (buffer[i] == '_') {
memmove(&buffer[i], &buffer[i+1], bufferSize - (i+1) + 1);
bufferSize--;
i--;
}
}
}
m_action(sender(), buffer, false);
app()->dismissModalViewController();
return true;
}