Skip to content

Commit

Permalink
Implement lazy search
Browse files Browse the repository at this point in the history
If no search term is given and one cell is selected and the user
triggers the search, use the cell text string as search query.

This is similiar to the F6 and F7 (jump to text/image) experience.

Also make the rootgrid check the first check for futureproofness.
  • Loading branch information
tobiolo committed Jan 6, 2024
1 parent a864136 commit 0af179c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,11 @@ struct Document {
return nullptr;
}

case A_SEARCHNEXT: {
return SearchNext(dc, false, true, false);
}

case A_SEARCHNEXT:
case A_SEARCHPREV: {
return SearchNext(dc, false, true, true);
return sys->searchstring.Len() ?
SearchNext(dc, false, true, k == A_SEARCHPREV) :
LoadSearch();
}

case A_CASESENSITIVESEARCH: {
Expand Down Expand Up @@ -2024,10 +2023,21 @@ struct Document {
}
}

const wxChar *LoadSearch() {
if (Cell *c = selected.GetCell()) {
if (!c->text.t.Len()) return _(L"No text in this cell.");
sys->frame->filter->SetFocus();
sys->frame->filter->SetValue(c->text.t);
return _(L"Search string was loaded from selection.");
} else {
return _(L"You need to select one cell if you want to search for its text.");
}
}

const wxChar *SearchNext(wxDC &dc, bool focusmatch, bool jump, bool reverse) {
if (!rootgrid) return nullptr; // fix crash when opening new doc
if (!sys->searchstring.Len()) return _(L"No search string.");
bool lastsel = true;
if (!rootgrid) return nullptr; //fix crash when opening new doc
Cell *next =
rootgrid->FindNextSearchMatch(sys->searchstring, nullptr, selected.GetCell(), lastsel, reverse);
sys->frame->SetSearchTextBoxBackgroundColour(next);
Expand Down

0 comments on commit 0af179c

Please sign in to comment.