From 030525fe63d48c015a204631fa1e2f1bca5d855a Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Sat, 26 Mar 2011 10:45:13 +0100 Subject: [PATCH] better fix for BZDNG-238, this time including the backspace key --- .../src/python_shell/python_shell_widget.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc index 8242f4a81..ef3e97090 100644 --- a/modules/gui/src/python_shell/python_shell_widget.cc +++ b/modules/gui/src/python_shell/python_shell_widget.cc @@ -474,6 +474,7 @@ void PythonShellWidget::OnExecuteStateEntered() set_block_type_(block_edit_start_,textCursor().block(),BLOCKTYPE_CODE); insertPlainText(QString(QChar::ParagraphSeparator)); QString command=GetCommand(); + QString command_trimmed=command.trimmed(); if (command_trimmed.size()>0) { unsigned int id=PythonInterpreter::Instance().RunCommand(command); @@ -482,7 +483,6 @@ void PythonShellWidget::OnExecuteStateEntered() insertPlainText(QString(QChar::ParagraphSeparator)); } block_edit_start_=textCursor().block(); - std::cout << block_edit_start_.isValid() << std::endl; } @@ -739,22 +739,29 @@ void PythonShellWidget::keyPressEvent(QKeyEvent* event) { // BZDNG-238 // 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 - // (b) Hit Backspace + // (b) Hit Backspace|Delete // (c) Hit Return // // 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(); if (cursor.hasSelection()) { cursor.removeSelectedText(); } else { 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(); return; } @@ -767,9 +774,11 @@ void PythonShellWidget::keyPressEvent(QKeyEvent* event) } } if (this->handle_custom_commands_(event)){ + event->accept(); return; } if (this->handle_completion_(event)){ + event->accept(); return; } QPlainTextEdit::keyPressEvent(event); -- GitLab