summaryrefslogtreecommitdiff
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2015-12-26 10:22:15 +0100
committerAndrea Azzarone <azzaronea@gmail.com>2015-12-26 10:22:15 +0100
commitf199616c2f1eb61acdeb987886ec34e108d3365f (patch)
tree865896b9b83d1b078be72053328462cfdd184baa
parent130cf4fc947debc5695dd20254799e9e97dbc56a (diff)
Propose a fix for bug #1154364. Patch originally proposed by Prasad Somwanshi.lp-1154364-incremental-search-fix
Fixes LP: #1154364 (bzr r4068)
-rw-r--r--unity-shared/SearchBar.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/unity-shared/SearchBar.cpp b/unity-shared/SearchBar.cpp
index 5ac9b5276..d9c77c8d1 100644
--- a/unity-shared/SearchBar.cpp
+++ b/unity-shared/SearchBar.cpp
@@ -48,6 +48,7 @@ namespace
const double DEFAULT_SCALE = 1.0;
const float DEFAULT_ICON_OPACITY = 1.0f;
const int DEFAULT_LIVE_SEARCH_TIMEOUT = 40;
+const int MAX_LIVE_SEARCH_TIMEOUT = 250;
const int SPINNER_TIMEOUT = 100;
const int CORNER_RADIUS = 5;
@@ -357,10 +358,20 @@ void SearchBar::OnSearchHintChanged()
void SearchBar::OnSearchChanged(nux::TextEntry* text_entry)
{
- // We don't want to set a new search string on every new character, so we add a sma
+ // We don't want to set a new search string on every new character, so we add a
// timeout to see if the user is typing a sentence. If more characters are added, we
- // keep restarting the timeout unti the user has actuay paused.
- live_search_timeout_.reset(new glib::Timeout(live_search_wait()));
+ // keep restarting the timeout until the user has actuay paused.
+ auto search_wait = DEFAULT_LIVE_SEARCH_TIMEOUT;
+ const std::string& search_text = pango_entry_->GetText();
+ auto search_text_len = search_text.size();
+
+ if (search_text_len > 0)
+ {
+ search_wait = MAX_LIVE_SEARCH_TIMEOUT / search_text_len;
+ search_wait = std::max(search_wait, DEFAULT_LIVE_SEARCH_TIMEOUT);
+ }
+
+ live_search_timeout_.reset(new glib::Timeout(search_wait));
live_search_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnLiveSearchTimeout));
// Don't animate the spinner immediately, the searches are fast and
@@ -368,14 +379,14 @@ void SearchBar::OnSearchChanged(nux::TextEntry* text_entry)
start_spinner_timeout_.reset(new glib::Timeout(SPINNER_TIMEOUT));
start_spinner_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnSpinnerStartCb));
- bool is_empty = pango_entry_->im_active() ? false : pango_entry_->GetText() == "";
+ bool is_empty = pango_entry_->im_active() ? false : search_text_len == 0;
hint_->SetVisible(is_empty);
pango_entry_->QueueDraw();
hint_->QueueDraw();
QueueDraw();
- search_changed.emit(pango_entry_->GetText());
+ search_changed.emit(search_text);
}
bool SearchBar::OnLiveSearchTimeout()