spotlight: ctrl-space, type a few letters, go
The dock is full and cannot grow. Once navigation lives here it is free to be a short list of what you actually use rather than a complete one — which is the other half of this and is not done yet. It INDEXES THE DOCK rather than keeping a list of its own. The dock is already the composed, permission-filtered answer to "what can this account open here": the shell's screens, plus whatever installed plugins contribute, minus anything canVisit refuses. A second list would be a second answer to one question, and it would be wrong the day somebody installs a plugin. So a new plugin appears in Spotlight for the reason it appears in the dock — because it is installed — and nothing here is edited. Settings sections are added, because they are what people hunt for and the dock deliberately does not carry them. Those ARE hand-listed, which is a real cost written down in the file: a section added to IntegrationsSettings will not appear until someone adds it here. The alternative couples five settings screens to the shell to save five lines. Matching is subsequence, not substring, and lives in its own file so it can be tested with strings: "chq" finds Command HQ, "apik" finds API keys, "fi" gives Files rather than Profile. The weights encode what "the right result" means — exact label, then prefix, then word boundaries, then adjacency, with shortness breaking ties so "Chat" beats "Chat history". Labels are worth about three times hints, and paths almost nothing, so a path fragment finds an item without ever outranking a real label. Nine tests cover the ORDER rather than the matching, because returning the right set is easy and returning it with the right thing first is the product. ctrl-space, not alt-space: the more macOS-shaped chord is already load-bearing for the owner. Not cmd-k either — that belongs to the browser on some platforms and to text fields on others. Mounted beside the header and the dock rather than inside the content region, so it still gets you off a screen that is maximised, erroring or mid-navigation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { rank } from './match';
|
||||
import type { SpotlightItem } from './useSpotlightItems';
|
||||
|
||||
// The behaviours a launcher is judged on, which are all about ORDER rather than about matching. Anyone
|
||||
// can return the right set; returning it with the right thing first is the whole product.
|
||||
|
||||
const item = (label: string, to: string, hint?: string): SpotlightItem => ({ id: to, label, to, hint });
|
||||
|
||||
const ITEMS: SpotlightItem[] = [
|
||||
item('Home', '/'),
|
||||
item('Files', '/files'),
|
||||
item('Chat', '/chat'),
|
||||
item('Command HQ', '/command-hq'),
|
||||
item('Editor', '/code-editor'),
|
||||
item('Profile', '/settings/profile', 'avatar, name, email'),
|
||||
item('API keys', '/settings/profile/api-keys', 'per-app keys'),
|
||||
item('App store', '/app-store'),
|
||||
item('Dashboards', '/dashboards'),
|
||||
];
|
||||
|
||||
const top = (query: string, n = 1) =>
|
||||
rank(ITEMS, query)
|
||||
.slice(0, n)
|
||||
.map((s) => s.item.label);
|
||||
|
||||
describe('spotlight ranking', () => {
|
||||
test('an exact label wins', () => {
|
||||
expect(top('chat')).toEqual(['Chat']);
|
||||
});
|
||||
|
||||
test('a prefix beats a scattered match — "fi" is Files, not Profile', () => {
|
||||
expect(top('fi')).toEqual(['Files']);
|
||||
});
|
||||
|
||||
test('initials find a two-word label — "chq" is Command HQ', () => {
|
||||
expect(top('chq')).toEqual(['Command HQ']);
|
||||
});
|
||||
|
||||
test('a subsequence works, so you can type the shape of a word', () => {
|
||||
expect(top('apik')).toEqual(['API keys']);
|
||||
});
|
||||
|
||||
test('a hint matches, but never outranks a label', () => {
|
||||
// "keys" is API keys' own label AND its hint. It must not be beaten by anything mentioning keys.
|
||||
expect(top('keys')).toEqual(['API keys']);
|
||||
});
|
||||
|
||||
test('a path fragment finds the item without outranking labels', () => {
|
||||
expect(rank(ITEMS, 'settings').map((s) => s.item.label)).toContain('Profile');
|
||||
// "app" is a prefix of "App store" and appears in API keys' hint ("per-app keys"). Label wins.
|
||||
expect(top('app')).toEqual(['App store']);
|
||||
});
|
||||
|
||||
test('nothing matches means nothing returned, not everything', () => {
|
||||
expect(rank(ITEMS, 'zzzzz')).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('an empty query keeps the given order rather than sorting it', () => {
|
||||
expect(rank(ITEMS, '').map((s) => s.item.label)).toEqual(ITEMS.map((i) => i.label));
|
||||
});
|
||||
|
||||
test('shorter labels break ties — "Chat" over "Chat history"', () => {
|
||||
const withLonger = [...ITEMS, item('Chat history', '/chat-history')];
|
||||
expect(rank(withLonger, 'chat')[0]!.item.label).toBe('Chat');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user