← Back to team overview

unity-dev team mailing list archive

Re: Bug #1154364

 

Find attached patch for this fix. Let me know what you think about it.My feeling is , it could do with initial time out value of between 250 ms and 500 ms. So that a meaningful query can be formed, before actually searching it. Haven't touched SearchBar::ForceLiveSearch.
 
 

Sent: Wednesday, November 04, 2015 at 2:44 PM
From: "Marco Trevisan" <marco.trevisan@xxxxxxxxxxxxx>
To: "Prasad Somwanshi" <prasad.s@xxxxxxxx>, unity-dev@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Unity-dev] Bug #1154364
Il 04/11/2015 15:38, Prasad Somwanshi ha scritto:
> Marco,
>
> Right now, there is pause of 40 ms , which is reset after each keystroke. To check is user is still typing in.
> My suggestion is a bit different.
> Depending on no of characters in search box, it should wait decresing no of ms before doing actual search.
>
> If user presses 'P', it's single character, so wait for 500 ms(or 250 ms), and there are more chances of use typing in more characters.
> Then user presses 'r'. We have 2 characters.(then wait for 250 ms(or 125 ms). Keep on reducing wait time as no of characters grows, and keep existing 40 ms as floor .
> So user may be able to do actual search 'prasad', without having to do search 'p' or 'pr' or 'pra'.
> So it will avoid effect of displaying result for non intended search words.

The idea it's not bad...
Maybe 500ms as starting point is too much, as sometimes I'd just want to
type "f", firefox spots and I hit enter, but we could indeed increase
this wait so that it's slower and then gets quicker.

If you want to contribute with a branch, it would be cool to review it.

Thanks
 
=== modified file 'unity-shared/SearchBar.cpp'
--- unity-shared/SearchBar.cpp	2014-09-04 22:11:33 +0000
+++ unity-shared/SearchBar.cpp	2015-11-03 22:59:38 +0000
@@ -48,6 +48,7 @@
 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;

@@ -392,10 +393,20 @@

 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 untill the user has actually paused.
+  // timeout value will be reduced as number of characters increased,
+  // with DEFAULT_LIVE_SEARCH_TIMEOUT as min timeout
+  size_t search_wait = DEFAULT_LIVE_SEARCH_TIMEOUT;
+  const std::string& text = pango_entry_->GetText();
+  size_t searchtext_len = text.size();
+  if (searchtext_len > 0)
+  {
+      search_wait = MAX_LIVE_SEARCH_TIMEOUT / searchtext_len;
+      search_wait = std::max(static_cast<int>(search_wait),DEFAULT_LIVE_SEARCH_TIMEOUT);
+  }
+  live_search_timeout_.reset(new glib::Timeout(live_search_wait(search_wait)));
   live_search_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnLiveSearchTimeout));

   // Don't animate the spinner immediately, the searches are fast and
@@ -403,14 +414,14 @@
   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 : searchtext_len == 0;
   hint_->SetVisible(is_empty);

   pango_entry_->QueueDraw();
   hint_->QueueDraw();
   QueueDraw();

-  search_changed.emit(pango_entry_->GetText());
+  search_changed.emit(text);
 }

 bool SearchBar::OnLiveSearchTimeout()


Follow ups

References