[code] Auto-indentation when inserting Toolbox items in scripts.

Change-Id: Id444ab91965999a3d322dee2fa58f73c86aa6992
This commit is contained in:
Léa Saviot
2017-11-13 11:19:42 +01:00
committed by Romain Goyet
parent 4f74b6d849
commit 59c840ef9a
3 changed files with 40 additions and 3 deletions

View File

@@ -42,11 +42,16 @@ App::App(Container * container, Snapshot * snapshot) :
m_codeStackViewController(&m_modalViewController, &m_listFooter),
m_toolboxActionForTextArea([](void * sender, const char * text) {
TextArea * textArea = static_cast<TextArea *>(sender);
textArea->insertText(text);
// insertText() also moves the cursor. We need to remove it to the
int previousCursorLocation = textArea->cursorLocation();
textArea->insertTextWithIndentation(text);
// insertText() also moves the cursor. We need to re-move it to the
// position we want (which is after the first parenthesis or before the
// first point).
int deltaCursorLocation = - (strlen(text) - Shared::ToolboxHelpers::CursorIndexInCommand(text));
int deltaCursorLocation = - textArea->cursorLocation() + previousCursorLocation + Shared::ToolboxHelpers::CursorIndexInCommand(text);
// WARNING: This is a dirty and only works because the cursor location we
// want is always on the first line of the text we insert. Because of the
// auto indentation, it would be difficult to compute the wanted cursor
// location on other lines of the text.
textArea->moveCursor(deltaCursorLocation);
}),
m_toolboxActionForTextField([](void * sender, const char * text) {