From 1d2d04246d04924f0409dfba603da82596a4ba1c Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Sat, 26 Mar 2011 10:08:07 +0100 Subject: [PATCH] don't crash in case of BZDNG-238 --- .../src/python_shell/python_shell_widget.cc | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc index f94f909c8..8242f4a81 100644 --- a/modules/gui/src/python_shell/python_shell_widget.cc +++ b/modules/gui/src/python_shell/python_shell_widget.cc @@ -482,7 +482,7 @@ void PythonShellWidget::OnExecuteStateEntered() insertPlainText(QString(QChar::ParagraphSeparator)); } block_edit_start_=textCursor().block(); - + std::cout << block_edit_start_.isValid() << std::endl; } @@ -737,6 +737,27 @@ QTextBlock PythonShellWidget::GetEditStartBlock() 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: + // + // (a) Hit Ctrl+A + // (b) Hit Backspace + // (c) Hit Return + // + // If we emulate the deletion of the text manually all is fine. + if (event->key()==Qt::Key_Backspace) { + QTextCursor cursor=this->textCursor(); + if (cursor.hasSelection()) { + cursor.removeSelectedText(); + } else { + if (cursor.position()>this->GetEditStartBlock().position()) { + cursor.deletePreviousChar(); + } + } + event->accept(); + return; + } // BZDNG-173 if (event->key()==Qt::Key_Left) { if (this->textCursor().position()==GetEditStartBlock().position() || -- GitLab