Skip to content
Snippets Groups Projects
Commit 030525fe authored by Marco Biasini's avatar Marco Biasini
Browse files

better fix for BZDNG-238, this time including the backspace key

parent 1d2d0424
No related branches found
Tags v0.2.0
No related merge requests found
...@@ -474,6 +474,7 @@ void PythonShellWidget::OnExecuteStateEntered() ...@@ -474,6 +474,7 @@ void PythonShellWidget::OnExecuteStateEntered()
set_block_type_(block_edit_start_,textCursor().block(),BLOCKTYPE_CODE); set_block_type_(block_edit_start_,textCursor().block(),BLOCKTYPE_CODE);
insertPlainText(QString(QChar::ParagraphSeparator)); insertPlainText(QString(QChar::ParagraphSeparator));
QString command=GetCommand(); QString command=GetCommand();
QString command_trimmed=command.trimmed(); QString command_trimmed=command.trimmed();
if (command_trimmed.size()>0) { if (command_trimmed.size()>0) {
unsigned int id=PythonInterpreter::Instance().RunCommand(command); unsigned int id=PythonInterpreter::Instance().RunCommand(command);
...@@ -482,7 +483,6 @@ void PythonShellWidget::OnExecuteStateEntered() ...@@ -482,7 +483,6 @@ void PythonShellWidget::OnExecuteStateEntered()
insertPlainText(QString(QChar::ParagraphSeparator)); insertPlainText(QString(QChar::ParagraphSeparator));
} }
block_edit_start_=textCursor().block(); block_edit_start_=textCursor().block();
std::cout << block_edit_start_.isValid() << std::endl;
} }
...@@ -739,22 +739,29 @@ void PythonShellWidget::keyPressEvent(QKeyEvent* event) ...@@ -739,22 +739,29 @@ void PythonShellWidget::keyPressEvent(QKeyEvent* event)
{ {
// BZDNG-238 // BZDNG-238
// Letting Qt do the handling of the backspace key leads to a crash when // Letting Qt do the handling of the backspace key leads to a crash when
// multiline block mode and doing the following: // editing a multiline block mode and doing the following:
// //
// (a) Hit Ctrl+A // (a) Hit Ctrl+A
// (b) Hit Backspace // (b) Hit Backspace|Delete
// (c) Hit Return // (c) Hit Return
// //
// If we emulate the deletion of the text manually all is fine. // If we emulate the deletion of the text manually all is fine.
if (event->key()==Qt::Key_Backspace) { if (event->key()==Qt::Key_Backspace || event->key()==Qt::Key_Delete) {
QTextCursor cursor=this->textCursor(); QTextCursor cursor=this->textCursor();
if (cursor.hasSelection()) { if (cursor.hasSelection()) {
cursor.removeSelectedText(); cursor.removeSelectedText();
} else { } else {
if (cursor.position()>this->GetEditStartBlock().position()) { if (cursor.position()>this->GetEditStartBlock().position()) {
cursor.deletePreviousChar(); if (event->key()==Qt::Key_Backspace) {
cursor.deletePreviousChar();
} else {
cursor.deleteChar();
}
} }
} }
QTextCursor tc=this->textCursor();
tc.setPosition(block_edit_start_.position());
block_edit_start_=tc.block();
event->accept(); event->accept();
return; return;
} }
...@@ -767,9 +774,11 @@ void PythonShellWidget::keyPressEvent(QKeyEvent* event) ...@@ -767,9 +774,11 @@ void PythonShellWidget::keyPressEvent(QKeyEvent* event)
} }
} }
if (this->handle_custom_commands_(event)){ if (this->handle_custom_commands_(event)){
event->accept();
return; return;
} }
if (this->handle_completion_(event)){ if (this->handle_completion_(event)){
event->accept();
return; return;
} }
QPlainTextEdit::keyPressEvent(event); QPlainTextEdit::keyPressEvent(event);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment