From f58b6f50ed634e37878363680c2d78aff7c00056 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 12 May 2015 14:46:20 +0200 Subject: [PATCH] ui: bug fixes in search bar * use DEL key to delete next element * cursor not jumping to end of word anymore when autocompletions are updated * holding down arrows for moving to start or end of word won't turn word into element fortune cookie message = You deserve to have a good time after a hard days work. --- src/app/qt/element/QtSmartSearchBox.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app/qt/element/QtSmartSearchBox.cpp b/src/app/qt/element/QtSmartSearchBox.cpp index a7a2a8b9..2c0e1389 100644 --- a/src/app/qt/element/QtSmartSearchBox.cpp +++ b/src/app/qt/element/QtSmartSearchBox.cpp @@ -63,9 +63,14 @@ QtSmartSearchBox::~QtSmartSearchBox() void QtSmartSearchBox::setAutocompletionList(const std::vector& autocompletionList) { + // Save the cursor position, because after activating the completer the cursor gets set to the end position. + int cursor = cursorPosition(); + QtAutocompletionList* completer = dynamic_cast(this->completer()); completer->completeAt(QPoint(textMargins().left() + 3, height() + 3), autocompletionList); + setCursorPosition(cursor); + connect(completer, SIGNAL(matchHighlighted(const SearchMatch&)), this, SLOT(onAutocompletionHighlighted(const SearchMatch&)), Qt::DirectConnection); connect(completer, SIGNAL(matchActivated(const SearchMatch&)), this, SLOT(onAutocompletionActivated(const SearchMatch&)), Qt::DirectConnection); @@ -153,6 +158,20 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event) return; } } + else if (event->matches(QKeySequence::Delete)) + { + if (hasSelectedElements()) + { + deleteSelectedElements(); + return; + } + else if (!hasSelectedText() && cursorPosition() == text().size() && m_cursorIndex < m_elements.size()) + { + m_elements[m_cursorIndex]->setChecked(true); + deleteSelectedElements(); + return; + } + } else if (event->matches(QKeySequence::MoveToPreviousChar)) { if (hasSelectedElements()) @@ -169,7 +188,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event) selectAllElementsWith(false); layoutElements(); } - else if (cursorPosition() == 0 && m_cursorIndex > 0) + else if (cursorPosition() == 0 && m_cursorIndex > 0 && !event->isAutoRepeat()) { editTextToElement(); moveCursor(-1); @@ -192,7 +211,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event) selectAllElementsWith(false); layoutElements(); } - else if (cursorPosition() == text().size()) + else if (cursorPosition() == text().size() && !event->isAutoRepeat()) { if (completer()->popup()->isVisible()) {