From d8e66449a62a2758d07b7b90f40a2470e440a3e8 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 26 Jun 2012 00:44:32 +0200 Subject: Ensure users can recover typed text in the urlbar PS: contains also an easy check improved to avoid duplicating suggestions creation ;) Thanks to Franz Fellner for REPORTING and FIXING himself the problem :D BUG: 302391 REVIEWED-BY: adjam --- src/urlbar/completionwidget.cpp | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index fa38d7f0..83de2f09 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -135,26 +135,26 @@ void CompletionWidget::popup() void CompletionWidget::up() { - // deactivate previous - findChild(QString::number(_currentIndex))->deactivate(); // deactivate previous - - if (_currentIndex > 0) - _currentIndex--; - else - _currentIndex = layout()->count() - 1; - + if (_currentIndex >= 0) + findChild(QString::number(_currentIndex))->deactivate(); // deactivate previous + + --_currentIndex; + if (_currentIndex < -1) { + _currentIndex = _list.count() - 1; + } + activateCurrentListItem(); } void CompletionWidget::down() { - findChild(QString::number(_currentIndex))->deactivate(); // deactivate previous + if(_currentIndex >= 0) + findChild(QString::number(_currentIndex))->deactivate(); // deactivate previous - if (_currentIndex < _list.count() - 1) - _currentIndex++; - else - _currentIndex = 0; + ++_currentIndex; + if (_currentIndex == _list.count()) + _currentIndex = -1; activateCurrentListItem(); } @@ -166,11 +166,18 @@ void CompletionWidget::activateCurrentListItem() // activate "new" current ListItem *widget = findChild(QString::number(_currentIndex)); - widget->activate(); - - //update text of the url bar - bar->blockSignals(true); //without compute suggestions - bar->setQUrl(widget->text()); + + // update text of the url bar + bar->blockSignals(true); // without compute suggestions + if (widget) + { + widget->activate(); + bar->setQUrl(widget->text()); + } + else + { + bar->setText(_typedString); + } bar->blockSignals(false); bar->setFocus(); bar->setCursorPosition(bar->text().length()); @@ -290,11 +297,12 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) } } - + kDebug() << "Suggestion INDEX chosen: " << _currentIndex; if (_currentIndex == -1) _currentIndex = 0; child = findChild(QString::number(_currentIndex)); - if (child && _currentIndex != 0) //the completionwidget is visible and the user had press down + + if (child) //the completionwidget is visible and the user had press down { //we can use the url of the listitem emit chosenUrl(child->url(), Rekonq::CurrentTab); -- cgit v1.2.1