fuzzy-match + recency-rank the command palette

Completes the command-palette acceptance: the filter is now a
subsequence fuzzy match (was substring), and recently-invoked commands
float to the top and break score ties. The subsequence matcher is
extracted to a shared fuzzy helper so the palette and quick-open file
finder use one implementation instead of a private copy each.

Pinned commands and cross-session recency persistence are left as a
follow-up (they need a pin affordance + settings storage).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-06 09:40:56 +02:00
co-authored by Claude
parent 968c3dbfa8
commit 0e85f7f5e7
8 changed files with 225 additions and 29 deletions
+35
View File
@@ -0,0 +1,35 @@
import 'package:clide/kernel/src/fuzzy.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('fuzzyScore', () {
test('empty query scores 0 (matches anything)', () {
expect(fuzzyScore('anything', ''), 0);
});
test('returns null when query is not a subsequence', () {
expect(fuzzyScore('git commit', 'xyz'), isNull);
expect(fuzzyScore('abc', 'abcd'), isNull); // query longer / extra char
});
test('matches non-contiguous subsequences', () {
expect(fuzzyScore('git commit', 'gc'), isNotNull);
expect(fuzzyScore('theme pick', 'tp'), isNotNull);
});
test('lower score is better: contiguous + early beats gappy + late', () {
final contiguousEarly = fuzzyScore('abcxxxx', 'abc')!; // match at 0,1,2
final gappyLate = fuzzyScore('xxxxabc', 'abc')!; // starts at 4
expect(contiguousEarly, lessThan(gappyLate));
final tight = fuzzyScore('ab', 'ab')!; // adjacent
final spread = fuzzyScore('axb', 'ab')!; // a gap between a and b
expect(tight, lessThan(spread));
});
test('case sensitivity is the caller\'s responsibility', () {
expect(fuzzyScore('GIT', 'git'), isNull); // differing case → no match
expect(fuzzyScore('GIT'.toLowerCase(), 'git'), isNotNull);
});
});
}