mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[code] Fixed cursor bug when inserting text in editor.
Now the cursor moves only if the insterion was successful. Change-Id: If2f74307aecd4b9b86183a3437a53fd8875c1751
This commit is contained in:
@@ -43,26 +43,26 @@ App::App(Container * container, Snapshot * snapshot) :
|
||||
m_toolboxActionForTextArea([](void * sender, const char * text) {
|
||||
TextArea * textArea = static_cast<TextArea *>(sender);
|
||||
int previousCursorLocation = textArea->cursorLocation();
|
||||
textArea->insertTextWithIndentation(text);
|
||||
if (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 = - textArea->cursorLocation() + previousCursorLocation + 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);
|
||||
}),
|
||||
textArea->moveCursor(deltaCursorLocation);
|
||||
}}),
|
||||
m_toolboxActionForTextField([](void * sender, const char * text) {
|
||||
TextField * textField = static_cast<TextField *>(sender);
|
||||
if (!textField->isEditing()) {
|
||||
textField->setEditing(true);
|
||||
}
|
||||
int newCursorLocation = textField->cursorLocation() + Shared::ToolboxHelpers::CursorIndexInCommand(text);
|
||||
textField->insertTextAtLocation(text, textField->cursorLocation());
|
||||
textField->setCursorLocation(newCursorLocation);
|
||||
})
|
||||
if (textField->insertTextAtLocation(text, textField->cursorLocation())) {
|
||||
textField->setCursorLocation(newCursorLocation);
|
||||
}})
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ bool EditorController::textAreaShouldFinishEditing(TextArea * textArea, Ion::Eve
|
||||
bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events::Event event) {
|
||||
const char * pythonText = Helpers::PythonTextForEvent(event);
|
||||
if (pythonText != nullptr) {
|
||||
textArea->insertText(pythonText);
|
||||
if (!textArea->insertText(pythonText)) {
|
||||
return false;
|
||||
}
|
||||
if (pythonText[strlen(pythonText)-1] == ')') {
|
||||
textArea->moveCursor(-1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user