Merge lp:~azzar1/unity/lp-1154364 into lp:unity

Proposed by Andrea Azzarone
Status: Needs review
Proposed branch: lp:~azzar1/unity/lp-1154364
Merge into: lp:unity
Diff against target: 52 lines (+16/-5)
1 file modified
unity-shared/SearchBar.cpp (+16/-5)
To merge this branch: bzr merge lp:~azzar1/unity/lp-1154364
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+281357@code.launchpad.net

Commit message

Propose a fix for bug #1154364. Patch originally proposed by Prasad Somwanshi.

Description of the change

Make search wait timeout depend on the search text length.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mateusz Stachowski (stachowski-mateusz) :
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Add a new property for the max live search timeout and use live_search_wait() property instead of the default value.

In this way we can change tweak these values in other views, such as the SpreadFilter where we probably want to use different values (let's define good ones for that as well).

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Andrea, can you please check the comments here?

Unmerged revisions

4068. By Andrea Azzarone

Propose a fix for bug #1154364. Patch originally proposed by Prasad Somwanshi.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-shared/SearchBar.cpp'
2--- unity-shared/SearchBar.cpp 2015-06-27 04:44:51 +0000
3+++ unity-shared/SearchBar.cpp 2015-12-26 09:30:45 +0000
4@@ -48,6 +48,7 @@
5 const double DEFAULT_SCALE = 1.0;
6 const float DEFAULT_ICON_OPACITY = 1.0f;
7 const int DEFAULT_LIVE_SEARCH_TIMEOUT = 40;
8+const int MAX_LIVE_SEARCH_TIMEOUT = 250;
9 const int SPINNER_TIMEOUT = 100;
10 const int CORNER_RADIUS = 5;
11
12@@ -357,10 +358,20 @@
13
14 void SearchBar::OnSearchChanged(nux::TextEntry* text_entry)
15 {
16- // We don't want to set a new search string on every new character, so we add a sma
17+ // We don't want to set a new search string on every new character, so we add a
18 // timeout to see if the user is typing a sentence. If more characters are added, we
19- // keep restarting the timeout unti the user has actuay paused.
20- live_search_timeout_.reset(new glib::Timeout(live_search_wait()));
21+ // keep restarting the timeout until the user has actuay paused.
22+ auto search_wait = DEFAULT_LIVE_SEARCH_TIMEOUT;
23+ const std::string& search_text = pango_entry_->GetText();
24+ auto search_text_len = search_text.size();
25+
26+ if (search_text_len > 0)
27+ {
28+ search_wait = MAX_LIVE_SEARCH_TIMEOUT / search_text_len;
29+ search_wait = std::max(search_wait, DEFAULT_LIVE_SEARCH_TIMEOUT);
30+ }
31+
32+ live_search_timeout_.reset(new glib::Timeout(search_wait));
33 live_search_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnLiveSearchTimeout));
34
35 // Don't animate the spinner immediately, the searches are fast and
36@@ -368,14 +379,14 @@
37 start_spinner_timeout_.reset(new glib::Timeout(SPINNER_TIMEOUT));
38 start_spinner_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnSpinnerStartCb));
39
40- bool is_empty = pango_entry_->im_active() ? false : pango_entry_->GetText() == "";
41+ bool is_empty = pango_entry_->im_active() ? false : search_text_len == 0;
42 hint_->SetVisible(is_empty);
43
44 pango_entry_->QueueDraw();
45 hint_->QueueDraw();
46 QueueDraw();
47
48- search_changed.emit(pango_entry_->GetText());
49+ search_changed.emit(search_text);
50 }
51
52 bool SearchBar::OnLiveSearchTimeout()