[code] Improved console command editing.

When the user scrolls the history, the draft command is not erased.
When pasting a previous command, the text is inserted at the cursor
location.

Change-Id: I1cd9645de74f34fad4ed0898203e05bd3352456a
This commit is contained in:
Léa Saviot
2017-11-07 17:31:44 +01:00
committed by Romain Goyet
parent 0d6cb75425
commit 2456c7eeba
5 changed files with 25 additions and 15 deletions

View File

@@ -98,9 +98,8 @@ void ConsoleController::didBecomeFirstResponder() {
bool ConsoleController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Up) {
if (m_consoleStore.numberOfLines() > 0) {
m_editCell.setEditing(false, true);
m_editCell.setText("");
if (m_consoleStore.numberOfLines() > 0 && m_selectableTableView.selectedRow() == m_consoleStore.numberOfLines()) {
m_editCell.setEditing(false);
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines()-1);
return true;
}
@@ -110,15 +109,10 @@ bool ConsoleController::handleEvent(Ion::Events::Event event) {
m_editCell.setEditing(true);
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines());
app()->setFirstResponder(&m_editCell);
m_editCell.setText(text);
return true;
return m_editCell.insertText(text);
}
} else if (event == Ion::Events::Copy) {
int row = m_selectableTableView.selectedRow();
if (row < m_consoleStore.numberOfLines()) {
Clipboard::sharedClipboard()->store(m_consoleStore.lineAtIndex(row).text());
return true;
}
return copyCurrentLineToClipboard();
}
return false;
}
@@ -204,7 +198,6 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve
if (pythonText == nullptr) {
return false;
}
textField->setEditing(true, false);
if (textField->insertTextAtLocation(pythonText, textField->cursorLocation())) {
textField->setCursorLocation(textField->cursorLocation()+strlen(pythonText));
if (pythonText[strlen(pythonText)-1] == ')') {
@@ -315,4 +308,14 @@ StackViewController * ConsoleController::stackViewController() {
return static_cast<StackViewController *>(parentResponder());
}
bool ConsoleController::copyCurrentLineToClipboard() {
int row = m_selectableTableView.selectedRow();
if (row < m_consoleStore.numberOfLines()) {
Clipboard::sharedClipboard()->store(m_consoleStore.lineAtIndex(row).text());
return true;
}
return false;
}
}