improve searching a bit / fix going to previous found position

This commit is contained in:
Andrzej Rybczak
2009-03-08 17:45:28 +01:00
parent 2c30387a91
commit 6be91a8216
2 changed files with 9 additions and 10 deletions

View File

@@ -599,6 +599,7 @@ template <class T> size_t NCurses::Menu<T>::RealChoice() const
template <class T> bool NCurses::Menu<T>::Search(const std::string &constraint, size_t beginning, bool case_sensitive) template <class T> bool NCurses::Menu<T>::Search(const std::string &constraint, size_t beginning, bool case_sensitive)
{ {
itsFound.clear(); itsFound.clear();
itsSearchConstraint.clear();
if (constraint.empty()) if (constraint.empty())
return false; return false;
itsSearchConstraint = constraint; itsSearchConstraint = constraint;
@@ -631,11 +632,7 @@ template <class T> void NCurses::Menu<T>::PrevFound(bool wrap)
return; return;
std::set<size_t>::iterator prev = itsFound.lower_bound(itsHighlight); std::set<size_t>::iterator prev = itsFound.lower_bound(itsHighlight);
if (prev != itsFound.begin()) if (prev != itsFound.begin())
{ Highlight(*--prev);
if (*prev == size_t(itsHighlight))
prev--;
Highlight(*prev);
}
else if (wrap) else if (wrap)
Highlight(*itsFound.rbegin()); Highlight(*itsFound.rbegin());
} }

View File

@@ -1489,14 +1489,16 @@ int main(int argc, char *argv[])
string findme = wFooter->GetString(mList->GetSearchConstraint()); string findme = wFooter->GetString(mList->GetSearchConstraint());
UnlockStatusbar(); UnlockStatusbar();
time(&Timer); time(&Timer);
if (!findme.empty())
ShowMessage("Searching...");
bool success = mList->Search(findme, myScreen == mySearcher ? SearchEngine::StaticOptions : 0);
if (findme.empty()) if (findme.empty())
continue; continue;
ShowMessage("Searching..."); success ? ShowMessage("Searching finished!") : ShowMessage("Unable to find \"%s\"", findme.c_str());
if (mList->Search(findme, myScreen == mySearcher ? SearchEngine::StaticOptions : 0))
ShowMessage("Searching finished!");
else
ShowMessage("Unable to find \"%s\"", findme.c_str());
if (Keypressed(input, Key.FindForward)) if (Keypressed(input, Key.FindForward))
mList->NextFound(Config.wrapped_search); mList->NextFound(Config.wrapped_search);