[apps/code] Fix varbox parentheses bug

Scenario: write i, open the varbox and select "in" -> parentheses are
added, but there shouldn't be any
This commit is contained in:
Léa Saviot
2020-04-22 16:18:23 +02:00
committed by Émilie Feral
parent e630b0e9e5
commit 7636c001e1

View File

@@ -337,10 +337,19 @@ bool VariableBoxController::selectLeaf(int rowIndex) {
assert(cellType == k_itemCellType);
(void)cellType; // Silence warnings
ScriptNode * selectedScriptNode = scriptNodeAtIndex(rowIndex - cumulatedOriginsCount); // Remove the number of subtitle cells from the index
/* We need to check now if we need to add parentheses: insertTextInCaller
* calls handleEventWithText, which will reload the autocompletion for the
* added text, which will probably chande the script nodes and
* selectedScriptNode will become invalid. */
const bool shouldAddParentheses = selectedScriptNode->type() == ScriptNode::Type::WithParentheses;
insertTextInCaller(selectedScriptNode->name() + m_shortenResultCharCount, selectedScriptNode->nameLength() - m_shortenResultCharCount);
if (selectedScriptNode->type() == ScriptNode::Type::WithParentheses) {
// WARNING: selectedScriptNode is now invalid
if (shouldAddParentheses) {
insertTextInCaller(ScriptNodeCell::k_parenthesesWithEmpty);
}
Container::activeApp()->dismissModalViewController();
return true;
}