From 091688d7c3e17e7a9980e225efcae22d212c53d3 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Tue, 14 Jul 2026 10:39:23 +0200 Subject: [PATCH] feat(editor): let a palette-query space match any separator Filenames use dashes where the typist thinks "space", so `la conv` now finds la-convergence.md (space matches / _ - . or space). --- editor/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/editor/src/lib.rs b/editor/src/lib.rs index abea2b0..fa023b9 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -552,6 +552,10 @@ fn wrap_text(text: &str, width: usize) -> Vec { /// though both contain the letters. There are no penalties, so a score is always /// ≥ the query length; ties are broken by the caller (recency, then list order). /// An empty query matches everything with score 0. +/// +/// A **space** in the query matches any separator (`/ _ - . space`), so typing +/// `la conv` finds `la-convergence.md` — filenames use `-` where the typist +/// thinks "space". fn fuzzy_score(query: &str, text: &str) -> Option { let q: Vec = query.chars().collect(); if q.is_empty() { @@ -562,7 +566,10 @@ fn fuzzy_score(query: &str, text: &str) -> Option { let mut prev_matched = false; let mut prev: Option = None; for (i, tc) in text.chars().enumerate() { - if qi < q.len() && tc.eq_ignore_ascii_case(&q[qi]) { + let hit = qi < q.len() + && (tc.eq_ignore_ascii_case(&q[qi]) + || (q[qi] == ' ' && matches!(tc, '/' | '_' | '-' | '.' | ' '))); + if hit { score += 1; let boundary = i == 0 || matches!(prev, Some('/') | Some('_') | Some('-') | Some('.') | Some(' ')); @@ -5519,6 +5526,14 @@ mod tests { assert_eq!(fuzzy_score("", "anything"), Some(0)); // empty query matches all } + #[test] + fn fuzzy_score_space_matches_any_separator() { + assert!(fuzzy_score("la conv", "repo/la-convergence.md").is_some()); // space finds '-' + assert!(fuzzy_score("notes md", "repo/notes.md").is_some()); // space finds '.' + assert!(fuzzy_score("repo notes", "repo/notes.md").is_some()); // space finds '/' + assert!(fuzzy_score("la conv", "repo/laconvergence.md").is_none()); // still needs a separator + } + #[test] fn fuzzy_score_ranks_word_boundaries_above_midword() { // "no" after the "/" boundary in repo/notes beats a mid-word hit.