Skip to content

Narrow a search from what it already found - #193

Open
OmarGonD wants to merge 1 commit into
omacom:mainfrom
OmarGonD:incremental-search
Open

OmarGonD wants to merge 1 commit into
omacom:mainfrom
OmarGonD:incremental-search

Conversation

@OmarGonD

Copy link
Copy Markdown
Contributor

Typing on in the search (beac to beach) or adding an ext: now keeps the matches that still fit, instead of walking the folder and everything below it again for each keystroke.

It only does this when the last search finished and wasn't cut short by the 1000-match limit, in the same folder with the same hidden-files and chooser-filter settings. Deleting characters, a different extension, or a new folder search again as before.

FolderModel::narrows() decides whether one query's matches are a subset of another's; it's tested, along with the model answering from what it found. bin/test passes.

Note for anything that adds query words whose matches don't only shrink as text is added (e.g. a dupes: filter): SearchFilter::narrowedBy is where to say so.

🤖 Generated with Claude Code

Typing on ("beac" to "beach") or adding an ext: keeps the matches that
still fit instead of walking the folder again, when the last search wasn't
cut short by the limit. Widening, or a change of folder, looks again.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change is limited to the file browser's folder-search workflow.

The PR appears safe to merge, with small follow-up fixes recommended for counts, Unicode extensions, and comments.

Findings

  1. P2 Folder counts stop updating ▶
  2. P2 Unicode extensions match differently ▶
  3. P2 Narrowing contract is backward ▶

Summary

Searches can now reuse completed results when a new query only narrows the matches.

  • Narrower folder searches reuse the matches already found.

Three small issues remain: unfinished folder counts are dropped, some Unicode extensions match differently, and the new helper's comments describe its contract backward.

Reviews (1) · Last reviewed commit: "Narrow a search from what it already fou..." · Reviewed by Greptile

Comment thread src/foldermodel.cpp
Comment on lines +898 to +900
setLoading(false);
emit loaded();
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Folder counts stop updating. Typing another character after a search finishes can cancel folder counts that are still running. reload() changes m_generation, so their results are discarded, but this early return never starts countFolders(generation) again. On large or slow folders, the remaining results can show no item counts until another full reload. Restart the unfinished counts before returning.

Comment thread src/foldermodel.cpp
const SearchFilter wanted(query);
QVector<Entry> kept;
for (const Entry &e : std::as_const(m_entries))
if (wanted.matches(QFileInfo(e.path).fileName(), e.isDir, e.extension))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unicode extensions match differently. This passes e.extension, which entryFor() has already uppercased, into a check that lowercases it again. That round trip changes some Unicode letters: a file named notes.ß stores SS, so narrowing notes to notes ext:ß incorrectly removes it, while a fresh search finds it. Use the original suffix from QFileInfo(e.path) rather than the display extension.

Comment thread src/foldermodel.h
Comment on lines +200 to +202
// Whether every match of the search `from` is also a match of `to`, so
// typing on ("beac" to "beach", or adding an ext:) can narrow what's
// already found instead of looking again.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Narrowing contract is backward. The comment says every from match must also match to, but the function requires the reverse: every to match must already match from. For example, beacon matches beac, but not beach, even though this pair correctly returns true. Reverse this description and the matching comment above SearchFilter::narrowedBy so future filters follow the right rule.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant