2026-09-28 19:37:41 -07:00
|
|
|
// Plan2Code Web Console - `@name` suggestions in a text box.
|
|
|
|
|
//
|
|
|
|
|
// Finds the `@partial` the caret sits in, filters the workspace's folder
|
|
|
|
|
// names against it, and splices a pick back into the text. The page owns the
|
|
|
|
|
// popover; this file owns the rules. No DOM access at module scope and no
|
|
|
|
|
// imports: the page and `node --test` both import this file.
|
|
|
|
|
|
Sync upstream web console updates into v2.4.2: on-demand Cleanup of unused ~/.plan2code files, an UPDATE AVAILABLE banner from the release tags, a colored launcher with a Planny banner, Notes threads that keep the person's notes and read older reply shapes, the repo-local plan2code-model-update maintainer skill, and review fixes (413 for oversize bodies, notes kept on skip, scoped reconnect banner, live Overview tab, busy state on 409, menu keyboard focus, case-insensitive mentions)
2026-10-05 19:10:45 -07:00
|
|
|
// Uppercase too: "@Repo" must still name @repo — names are forced lowercase
|
|
|
|
|
// by the workspace rules, and a query typed with a capital otherwise matches
|
|
|
|
|
// nothing and opens no suggestions at all.
|
|
|
|
|
const NAME_CHAR = /[a-z0-9-]/i;
|
2026-09-28 19:37:41 -07:00
|
|
|
const MAX_MATCHES = 6;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The mention the caret is in: `{ start, query }`, where `start` is the index
|
|
|
|
|
* of the `@`, or null. The `@` must open the text or follow whitespace or
|
|
|
|
|
* `(`, so an email address never offers suggestions.
|
|
|
|
|
*/
|
|
|
|
|
export function mentionAt(text, caret) {
|
|
|
|
|
let i = caret;
|
|
|
|
|
while (i > 0 && NAME_CHAR.test(text[i - 1])) i--;
|
|
|
|
|
const at = i - 1;
|
|
|
|
|
if (at < 0 || text[at] !== "@") return null;
|
|
|
|
|
if (at > 0 && !/[\s(]/.test(text[at - 1])) return null;
|
|
|
|
|
return { start: at, query: text.slice(i, caret) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Names starting with the query first, then names containing it, in the
|
Sync upstream web console updates into v2.4.2: on-demand Cleanup of unused ~/.plan2code files, an UPDATE AVAILABLE banner from the release tags, a colored launcher with a Planny banner, Notes threads that keep the person's notes and read older reply shapes, the repo-local plan2code-model-update maintainer skill, and review fixes (413 for oversize bodies, notes kept on skip, scoped reconnect banner, live Overview tab, busy state on 409, menu keyboard focus, case-insensitive mentions)
2026-10-05 19:10:45 -07:00
|
|
|
// order given, at most six. Case-folded: folder names are lowercase by rule,
|
|
|
|
|
// and "@Repo" should still find @repo rather than claim nothing matches.
|
2026-09-28 19:37:41 -07:00
|
|
|
export function matchNames(names, query) {
|
Sync upstream web console updates into v2.4.2: on-demand Cleanup of unused ~/.plan2code files, an UPDATE AVAILABLE banner from the release tags, a colored launcher with a Planny banner, Notes threads that keep the person's notes and read older reply shapes, the repo-local plan2code-model-update maintainer skill, and review fixes (413 for oversize bodies, notes kept on skip, scoped reconnect banner, live Overview tab, busy state on 409, menu keyboard focus, case-insensitive mentions)
2026-10-05 19:10:45 -07:00
|
|
|
const q = String(query || "").toLowerCase();
|
|
|
|
|
const fold = (n) => String(n).toLowerCase();
|
|
|
|
|
const prefix = names.filter((n) => fold(n).startsWith(q));
|
|
|
|
|
const inside = names.filter((n) => !fold(n).startsWith(q) && fold(n).includes(q));
|
2026-09-28 19:37:41 -07:00
|
|
|
return [...prefix, ...inside].slice(0, MAX_MATCHES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The text with `@partial` replaced by `@name `, and the caret after the space.
|
|
|
|
|
export function applyMention(text, caret, mention, name) {
|
|
|
|
|
const insert = `@${name} `;
|
|
|
|
|
return {
|
|
|
|
|
text: text.slice(0, mention.start) + insert + text.slice(caret),
|
|
|
|
|
caret: mention.start + insert.length,
|
|
|
|
|
};
|
|
|
|
|
}
|