Skip to content

Commit

Permalink
Implement lazy search (#581)
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 authored Jan 6, 2024
1 parent a864136 commit e69bebf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,17 @@ 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);
if (sys->searchstring.Len()) return SearchNext(dc, false, true, k == A_SEARCHPREV);
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 nullptr;
} else {
return _(L"You need to select one cell if you want to search for its text.");
}
}

case A_CASESENSITIVESEARCH: {
Expand Down Expand Up @@ -2025,9 +2030,9 @@ struct Document {
}

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 e69bebf

Please sign in to comment.