From 9ddf52013708caa86564e82eee4d5b04b3e5164a Mon Sep 17 00:00:00 2001 From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Fri, 11 Jun 2010 11:57:28 +0000 Subject: [PATCH] fix problem when deleting selection with backspace When backspace is pressed and the cursor position is equal to the start of the edit block, the selected text was not deleted as it should. Instead of testing for textCursor().position() we now use textCursor().selectionStart() which is always equal to the start of the selection. In case no text is selected, it is equal to position(). Andi, please review. git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2381 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gui/src/python_shell/python_shell_widget.cc | 2 +- modules/gui/src/python_shell/transition.cc | 3 ++- modules/gui/src/python_shell/transition_guard.cc | 9 ++++++--- modules/gui/src/python_shell/transition_guard.hh | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc index a1ee30cb5..534afecda 100644 --- a/modules/gui/src/python_shell/python_shell_widget.cc +++ b/modules/gui/src/python_shell/python_shell_widget.cc @@ -135,7 +135,7 @@ void PythonShellWidget::setup_readonly_state_machine_() Qt::NoModifier, readwrite_state_, true, - new EditPositionGuard(this,EditPositionGuard::EQUAL)))); + new EditPositionGuard(this,EditPositionGuard::EQUAL|EditPositionGuard::SELECTION)))); connect(readonly,SIGNAL(entered()),this,SLOT(OnReadonlyEntered())); connect(readwrite_state_,SIGNAL(entered()),this,SLOT(OnReadwriteEntered())); readonly_machine_->setInitialState(readwrite_state_); diff --git a/modules/gui/src/python_shell/transition.cc b/modules/gui/src/python_shell/transition.cc index 57559da98..e39ac8099 100644 --- a/modules/gui/src/python_shell/transition.cc +++ b/modules/gui/src/python_shell/transition.cc @@ -61,7 +61,8 @@ KeyEventTransition::KeyEventTransition(QEvent::Type type,int key,Qt::KeyboardMod std::pair<bool,bool> KeyEventTransition::checkEvent(QKeyEvent* event) { assert(is_active_()); - if(event->type()==type_ && (event->key()==key_ || key_==Qt::Key_Any) && event->modifiers() == modifiers_ && guard_->check()){ + if(event->type()==type_ && (event->key()==key_ || + key_==Qt::Key_Any) && event->modifiers() == modifiers_ && guard_->check()){ trigger_(); return std::pair<bool,bool>(true,swallow_); } diff --git a/modules/gui/src/python_shell/transition_guard.cc b/modules/gui/src/python_shell/transition_guard.cc index 4409dfe3b..765cb5f67 100644 --- a/modules/gui/src/python_shell/transition_guard.cc +++ b/modules/gui/src/python_shell/transition_guard.cc @@ -37,14 +37,17 @@ EditPositionGuard::EditPositionGuard(PythonShellWidget* shell, int flags): bool EditPositionGuard::check() { bool returnflag=false; + QTextCursor tc=shell_->textCursor(); if(flags_ & SMALLER){ - returnflag |= shell_->textCursor().position()< shell_->GetEditStartBlock().position(); + returnflag|=tc.selectionStart()<shell_->GetEditStartBlock().position(); } if(flags_ & EQUAL){ - returnflag |= shell_->textCursor().position()== shell_->GetEditStartBlock().position(); + if (!(flags_ & SELECTION && tc.hasSelection())) { + returnflag|=tc.selectionStart()==shell_->GetEditStartBlock().position(); + } } if(flags_ & BIGGER){ - returnflag |= shell_->textCursor().position()> shell_->GetEditStartBlock().position(); + returnflag |= tc.selectionStart()> shell_->GetEditStartBlock().position(); } return returnflag; } diff --git a/modules/gui/src/python_shell/transition_guard.hh b/modules/gui/src/python_shell/transition_guard.hh index d3e90b9a3..5ae202ca5 100644 --- a/modules/gui/src/python_shell/transition_guard.hh +++ b/modules/gui/src/python_shell/transition_guard.hh @@ -40,7 +40,8 @@ public: enum FLAGS{ SMALLER=1, EQUAL=2, - BIGGER=4 + BIGGER=4, + SELECTION=8 }; EditPositionGuard(PythonShellWidget* shell,int flags); virtual bool check(); -- GitLab