feat(ux): unify "Ask Claude to Edit" + inline prompt at selection; fix keybindings (#62)

This commit was merged in pull request #62.
This commit is contained in:
2026-06-26 12:11:43 +00:00
parent a42e5f145d
commit 9432300e3c
9 changed files with 285 additions and 80 deletions
@@ -28,7 +28,10 @@ suite("no-workspace authoring (F8 — real folder-less, #8 lineage)", () => {
"cowriting.reply",
"cowriting.resolveThread",
"cowriting.reopenThread",
"cowriting.edit",
"cowriting.editSelection",
"cowriting.askClaude.submit",
"cowriting.askClaude.cancel",
"cowriting.applyAgentEdit",
"cowriting.proposeAgentEdit",
]) {
+14 -8
View File
@@ -174,16 +174,22 @@ suite("F11 preview toolbar (host E2E — message → seam wiring, no LLM)", () =
assert.strictEqual(api.proposalController.listProposals(doc).length, 0, "no proposals left pending");
});
// SLICE-3: the document-scoped command exists for #42 reuse, guarded on markdown.
test("cowriting.editDocument is a registered command, palette-guarded on markdown", async () => {
// SLICE-3: the document-scoped command stays registered for #42 reuse (now behind
// the unified `cowriting.edit`). editDocument is hidden from the palette; the
// markdown-guarded user-facing palette command is `cowriting.edit`.
test("cowriting.editDocument stays registered; cowriting.edit is the markdown-guarded palette command", async () => {
const all = await vscode.commands.getCommands(true);
assert.ok(all.includes("cowriting.editDocument"), "editDocument command registered");
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../../package.json"), "utf8"));
const entry = (pkg.contributes.menus.commandPalette as Array<{ command: string; when?: string }>).find(
(m) => m.command === "cowriting.editDocument",
);
assert.ok(entry, "editDocument has a commandPalette entry");
assert.match(entry!.when ?? "", /editorLangId == markdown/, "guarded on markdown");
assert.ok(all.includes("cowriting.edit"), "unified edit command registered");
const palette = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../../package.json"), "utf8")).contributes
.menus.commandPalette as Array<{ command: string; when?: string }>;
// editDocument is hidden (routed via cowriting.edit).
const docEntry = palette.find((m) => m.command === "cowriting.editDocument");
assert.strictEqual(docEntry?.when, "false", "editDocument hidden from the palette");
// cowriting.edit is the user-facing, markdown-guarded entry.
const editEntry = palette.find((m) => m.command === "cowriting.edit");
assert.ok(editEntry, "cowriting.edit has a commandPalette entry");
assert.match(editEntry!.when ?? "", /editorLangId == markdown/, "guarded on markdown");
});
// SLICE-5: the minimal right-click gateway lives in editor/title (markdown only).
+32 -38
View File
@@ -31,43 +31,37 @@ function menu(id: string): Array<{ command: string; when?: string; group?: strin
}
// SLICE-1 / #42 (reach): "Ask Claude to Edit" reachable from the editor BODY and
// the editor TAB, selection-aware (selection → editSelection; no selection →
// editDocument), both markdown/authorable-gated, both routing through the single
// runEditAndPropose path (INV-38). The menu `when` clauses are declarative, so we
// assert them directly; the tab-targeting behavior is exercised through the command.
// the editor TAB. The two split commands (editSelection / editDocument) were
// unified behind ONE user-facing command `cowriting.edit` that auto-routes by
// selection at runtime (routeEdit: selection → editSelection, none → editDocument)
// — so the menus carry a SINGLE selection-agnostic entry, both markdown/authorable
// -gated. The routing itself is unit-tested (routeEdit) and exercised through the
// command below; here we assert the declarative menu `when` clauses.
suite("F12 SLICE-1 — Ask-Claude reach (#42, INV-38)", () => {
// PUC-1/2: editor BODY (editor/context) is selection-aware + markdown-gated.
test("editor/context offers editSelection (with selection) and editDocument (without), markdown+authorable", () => {
// PUC-1/2: editor BODY (editor/context) offers the single unified entry,
// markdown + authorable gated, NOT selection-gated (it routes both cases).
test("editor/context offers a single 'Ask Claude to Edit' (cowriting.edit), markdown+authorable", () => {
const m = menu("editor/context");
const sel = m.find((e) => e.command === "cowriting.editSelection");
const doc = m.find((e) => e.command === "cowriting.editDocument");
assert.ok(sel, "editSelection is in editor/context");
assert.ok(doc, "editDocument is in editor/context");
assert.match(sel!.when ?? "", /editorHasSelection/, "editSelection shows only with a selection");
assert.ok(!/!\s*editorHasSelection/.test(sel!.when ?? ""), "editSelection is not gated on NO selection");
assert.match(sel!.when ?? "", /editorLangId == markdown/, "editSelection gated on markdown");
assert.match(sel!.when ?? "", /resourceScheme == file|resourceScheme == untitled/, "editSelection gated authorable");
assert.match(doc!.when ?? "", /!\s*editorHasSelection/, "editDocument shows only without a selection");
assert.match(doc!.when ?? "", /editorLangId == markdown/, "editDocument gated on markdown");
assert.match(doc!.when ?? "", /resourceScheme == file|resourceScheme == untitled/, "editDocument gated authorable");
const edit = m.find((e) => e.command === "cowriting.edit");
assert.ok(edit, "cowriting.edit is in editor/context");
assert.match(edit!.when ?? "", /editorLangId == markdown/, "gated on markdown");
assert.match(edit!.when ?? "", /resourceScheme == file|resourceScheme == untitled/, "gated authorable");
assert.ok(!/editorHasSelection/.test(edit!.when ?? ""), "not selection-gated — one entry routes both cases");
// The old split pair is gone from the menu (the commands stay registered/hidden).
assert.ok(!m.some((e) => e.command === "cowriting.editSelection"), "old editSelection menu entry removed");
assert.ok(!m.some((e) => e.command === "cowriting.editDocument"), "old editDocument menu entry removed");
});
// PUC-3: editor TAB (editor/title/context) carries the same selection-aware pair.
test("editor/title/context offers editSelection (with selection) and editDocument (without), markdown-gated", () => {
// PUC-3: editor TAB (editor/title/context) carries the same single entry.
test("editor/title/context offers a single 'Ask Claude to Edit' (cowriting.edit), markdown-gated", () => {
const m = menu("editor/title/context");
const sel = m.find((e) => e.command === "cowriting.editSelection");
const doc = m.find((e) => e.command === "cowriting.editDocument");
assert.ok(sel, "editSelection is in editor/title/context");
assert.ok(doc, "editDocument is in editor/title/context");
assert.match(sel!.when ?? "", /editorHasSelection/, "tab editSelection shows only with a selection");
assert.ok(!/!\s*editorHasSelection/.test(sel!.when ?? ""), "tab editSelection is not gated on NO selection");
assert.match(sel!.when ?? "", /resourceLangId == markdown/, "tab editSelection gated on markdown");
assert.match(doc!.when ?? "", /!\s*editorHasSelection/, "tab editDocument shows only without a selection");
assert.match(doc!.when ?? "", /resourceLangId == markdown/, "tab editDocument gated on markdown");
const edit = m.find((e) => e.command === "cowriting.edit");
assert.ok(edit, "cowriting.edit is in editor/title/context");
assert.match(edit!.when ?? "", /resourceLangId == markdown/, "tab entry gated on markdown");
assert.ok(
!m.some((e) => e.command === "cowriting.editSelection" || e.command === "cowriting.editDocument"),
"old split pair removed from the tab menu",
);
});
// PUC-3 behavior: editDocument invoked with a tab URI targets THAT document,
@@ -83,8 +77,8 @@ suite("F12 SLICE-1 — Ask-Claude reach (#42, INV-38)", () => {
await settle();
// Stub the instruction prompt (sealed input box can't run in CI) + the LLM turn.
const origInput = vscode.window.showInputBox;
(vscode.window as any).showInputBox = async () => "rewrite it";
const origPrompt = api.inlineAsk.prompt;
(api.inlineAsk as any).prompt = async () => "rewrite it";
ctl.setEditTurnForTest(async () => ({
replacement: "# Tab\n\nThe REWRITTEN tab paragraph.\n",
model: "sonnet",
@@ -94,7 +88,7 @@ suite("F12 SLICE-1 — Ask-Claude reach (#42, INV-38)", () => {
await vscode.commands.executeCommand("cowriting.editDocument", b.doc.uri);
await settle();
} finally {
(vscode.window as any).showInputBox = origInput;
(api.inlineAsk as any).prompt = origPrompt;
}
// The proposal(s) landed on the TAB doc (B), and the ACTIVE doc (A) has none.
@@ -116,8 +110,8 @@ suite("F12 SLICE-1 — Ask-Claude reach (#42, INV-38)", () => {
await vscode.window.showTextDocument(a.doc);
await settle();
const origInput = vscode.window.showInputBox;
(vscode.window as any).showInputBox = async () => "rewrite it";
const origPrompt = api.inlineAsk.prompt;
(api.inlineAsk as any).prompt = async () => "rewrite it";
ctl.setEditTurnForTest(async () => ({
replacement: "# No arg\n\nThe REWRITTEN active doc paragraph.\n",
model: "sonnet",
@@ -127,7 +121,7 @@ suite("F12 SLICE-1 — Ask-Claude reach (#42, INV-38)", () => {
await vscode.commands.executeCommand("cowriting.editDocument");
await settle();
} finally {
(vscode.window as any).showInputBox = origInput;
(api.inlineAsk as any).prompt = origPrompt;
}
assert.ok(api.proposalController.listProposals(a.doc).length >= 1, "active doc received the proposal(s) on no-arg");
});