diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc
index 8242f4a81d23412edd0d92ce6f8289b7809b5f5d..ef3e9709067f206ba21a79f4f9c327033094343c 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);