* fix(pi-fff): preserve path and exclude constraints in fuzzy grep fallback (#697) The automatic fuzzy fallback in the pi-fff `grep` tool passed the raw `pattern` to `picker.grep`, discarding the constrained `query` built via `buildQuery`. As a result, the fallback ignored the caller's `path` and `exclude` constraints and could return matches from explicitly excluded directories or files outside the requested path. Pass the constrained `query` to the fallback instead, so it only broadens matching (fuzzy vs. plain) without broadening scope. Closes #697 * fix(pi-fff): drop path constraint in fuzzy fallback only for file paths When the caller pinned a specific file (path has an extension), the fuzzy fallback broadens across the whole picker so a mistyped filename can still surface matches. For directory constraints (or no path), keep the constrained query so the fallback does not leak matches from excluded / out-of-scope directories. --------- Co-authored-by: gustav-fff <286169375+gustav-fff@users.noreply.github.com>
This commit is contained in:
@@ -722,7 +722,15 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
|
||||
// automatic fuzzy fallback allows to broad the queries and find different cases
|
||||
if (result.items.length === 0 && !params.cursor && mode !== "regex") {
|
||||
const fuzzy = picker.grep(pattern, {
|
||||
// When the caller pinned a specific file (path has an extension), the
|
||||
// fuzzy fallback broadens across the whole picker — the file may just
|
||||
// be misnamed. For directory constraints (or no path), we keep the
|
||||
// constrained query so the fallback does not leak matches from
|
||||
// excluded / out-of-scope directories.
|
||||
const lastSeg = params.path?.split(/[\\/]/).pop() ?? "";
|
||||
const pathTargetsFile = /\.[a-zA-Z][a-zA-Z0-9]{0,9}$/.test(lastSeg);
|
||||
const fuzzyQuery = pathTargetsFile ? pattern : query;
|
||||
const fuzzy = picker.grep(fuzzyQuery, {
|
||||
mode: "fuzzy",
|
||||
smartCase,
|
||||
maxMatchesPerFile: Math.min(effectiveLimit, 50),
|
||||
|
||||
Reference in New Issue
Block a user