mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-18 13:01:18 -08:00
Focus a Markdown box on a click anywhere inside its border
AI Assisted
This commit is contained in:
1 parent
bf8dea9942
commit
9cbb970552
4 files changed
+120
-1
No files matched your search
@@ -16,6 +16,11 @@
|
||||
- About: scripts/test-web-console-shape.mjs, .agents-docs/AGENTS-architecture-console-page.md
|
||||
- Noted: 2026-11-14, implement-review
|
||||
|
||||
### A no-hop dashboard request goes as a __<name> send; the agent answers with a top-level patch key checked in validate() (patches.mjs), and pointersForSend() maps it to console-launches.md.
|
||||
- Kind: convention
|
||||
- About: src/web-console/patches.mjs, src/web-console/pointers.mjs
|
||||
- Noted: 2026-11-17, quick-task
|
||||
|
||||
### A test run of node install.js with a temp HOME still writes the plan2code shims into the real npm global bin, because npm's prefix does not follow HOME; also set npm_config_prefix to a temp folder.
|
||||
- Kind: correction
|
||||
- About: install.js
|
||||
@@ -27,6 +32,11 @@
|
||||
- About: install.js
|
||||
- Noted: 2026-11-17, implement-review
|
||||
|
||||
### In a Markdown field (md-field.js), CodeMirror's scroller and content are only as tall as the text, not the bordered host: code that hit-tests the scroller must not assume it fills the box.
|
||||
- Kind: how-it-works
|
||||
- About: src/web-console/public/md-field.js
|
||||
- Noted: 2026-11-17, quick-task
|
||||
|
||||
### In a node:test file, start fixtures such as a test server in a root before hook, never with a top-level await after the first test(), which lets the runner run after hooks early
|
||||
- Kind: correction
|
||||
- About: scripts/test-script-deps.mjs
|
||||
|
||||
@@ -60,6 +60,62 @@ test("the answer box renders Markdown live, like the Notebook", async (t) => {
|
||||
assert.deepEqual(answerTo(got, "q1"), { text: "**bold**\nplain" });
|
||||
});
|
||||
|
||||
test("a click anywhere inside the answer box's border focuses it, not only on the text line", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "plan",
|
||||
payload: { items: [{ id: "q1", kind: "text", title: "What to build", body: "Describe it.", placeholder: "One line of hint." }] },
|
||||
});
|
||||
const card = itemCard(s.page, "q1");
|
||||
const host = card.locator(".md-host").first();
|
||||
const content = host.locator(".cm-content");
|
||||
await content.waitFor({ timeout: 15000 });
|
||||
await settled(s.page, "#main");
|
||||
const box = await host.boundingBox();
|
||||
const line = await content.boundingBox();
|
||||
assert.ok(box.height - line.height > 30, "the box is taller than its one line of text, leaving empty space to click");
|
||||
// Low in the box, well below the text line and clear of the resize grip.
|
||||
await s.page.mouse.click(box.x + box.width / 2, box.y + box.height - 12);
|
||||
assert.equal(await host.evaluate((el) => el === document.activeElement), true, "the box took the focus");
|
||||
await s.page.keyboard.type("typed after a low click");
|
||||
assert.equal(await host.evaluate((el) => el.field.value), "typed after a low click");
|
||||
});
|
||||
|
||||
test("a press in the empty part of the answer box selects like a textarea: Shift extends, a drag selects, a double click takes the word", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "plan",
|
||||
payload: { items: [{ id: "q1", kind: "text", title: "What to build", body: "Describe it." }] },
|
||||
});
|
||||
const host = itemCard(s.page, "q1").locator(".md-host").first();
|
||||
const content = host.locator(".cm-content");
|
||||
await content.waitFor({ timeout: 15000 });
|
||||
await settled(s.page, "#main");
|
||||
await content.click();
|
||||
await s.page.keyboard.type("hello world");
|
||||
const range = () => host.evaluate((el) => [el.field.selectionStart, el.field.selectionEnd]);
|
||||
const box = await host.boundingBox();
|
||||
const low = { x: box.x + box.width / 2, y: box.y + box.height - 12 };
|
||||
assert.equal(await host.evaluate((el) => getComputedStyle(el).cursor), "text", "the whole box shows the text pointer");
|
||||
|
||||
await s.page.keyboard.press("Home");
|
||||
// page.mouse takes no modifiers option: hold Shift on the keyboard.
|
||||
await s.page.keyboard.down("Shift");
|
||||
await s.page.mouse.click(low.x, low.y);
|
||||
await s.page.keyboard.up("Shift");
|
||||
assert.deepEqual(await range(), [0, 11], "Shift+click below the text extends from the caret");
|
||||
|
||||
const line = await content.boundingBox();
|
||||
await s.page.mouse.move(low.x, low.y);
|
||||
await s.page.mouse.down();
|
||||
await s.page.mouse.move(line.x + 2, line.y + line.height / 2, { steps: 5 });
|
||||
await s.page.mouse.up();
|
||||
assert.deepEqual(await range(), [0, 11], "a drag from below the text up to its start selects it");
|
||||
|
||||
await s.page.mouse.dblclick(low.x, low.y);
|
||||
assert.deepEqual(await range(), [6, 11], "a double click below the text takes the last word");
|
||||
});
|
||||
|
||||
// The agent's side of one question: settle what came before, post `item`
|
||||
// alone, and wait for its card.
|
||||
async function ask(s, item) {
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
inherited min-height inside a bordered host counts the border twice. The
|
||||
height: auto resets cut notepad-editor.css's height: 100% rules, which this
|
||||
sheet is loaded beside and must never inherit sizing from. */
|
||||
:host { display: flex; flex-direction: column; height: auto; }
|
||||
/* cursor: a press anywhere inside the border goes to the text (md-field.js),
|
||||
so the whole box shows the text pointer; .md-host.is-disabled outside wins. */
|
||||
:host { display: flex; flex-direction: column; height: auto; cursor: text; }
|
||||
.md-field { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
|
||||
.cm-editor { flex: 1 1 auto; min-height: 0; height: auto; background: transparent; color: var(--ink); font: inherit; }
|
||||
div.cm-editor.cm-focused { outline: none; }
|
||||
|
||||
@@ -233,6 +233,57 @@ export function makeMdField({ id, className, value = "", placeholder: hint, labe
|
||||
if (view) view.destroy();
|
||||
},
|
||||
};
|
||||
// The editable line is only as tall as its text, so a press in the empty
|
||||
// space below it (or on the frame's padding) would land on the scroller,
|
||||
// which takes no focus. Anywhere inside the border counts as the box: focus
|
||||
// it and put the caret at the nearest spot. Left alone: presses on the text
|
||||
// itself (CodeMirror's own), the resize grip in the bottom-right corner and
|
||||
// a scrollbar, whose drags a preventDefault would break.
|
||||
host.addEventListener("mousedown", (event) => {
|
||||
if (!view || off || event.button !== 0) return;
|
||||
if (event.composedPath().includes(view.contentDOM)) return;
|
||||
const box = host.getBoundingClientRect();
|
||||
if (box.right - event.clientX < 18 && box.bottom - event.clientY < 18) return;
|
||||
const scroller = view.scrollDOM;
|
||||
const sb = scroller.getBoundingClientRect();
|
||||
const inside = (x, y) => x >= sb.left && x < sb.right && y >= sb.top && y < sb.bottom;
|
||||
const onBar =
|
||||
inside(event.clientX, event.clientY) &&
|
||||
(event.clientX >= sb.left + scroller.clientLeft + scroller.clientWidth || event.clientY >= sb.top + scroller.clientTop + scroller.clientHeight);
|
||||
if (onBar) return;
|
||||
event.preventDefault();
|
||||
// The preventDefault also stops the browser's own selecting, and
|
||||
// CodeMirror listens only on the text, so what a textarea does with a
|
||||
// press is done here: Shift extends, a double click takes the word, a
|
||||
// triple click the line, and a drag selects up to wherever it goes.
|
||||
const where = (e) => view.posAtCoords({ x: e.clientX, y: e.clientY }, false) ?? view.state.doc.length;
|
||||
const at = where(event);
|
||||
const pick = (selection) => view.dispatch({ selection, userEvent: "select.pointer" });
|
||||
view.focus();
|
||||
if (event.detail >= 3) {
|
||||
const line = view.state.doc.lineAt(at);
|
||||
pick({ anchor: line.from, head: line.to });
|
||||
return;
|
||||
}
|
||||
if (event.detail === 2) {
|
||||
const word = view.state.wordAt(at);
|
||||
pick(word ? { anchor: word.from, head: word.to } : { anchor: at });
|
||||
return;
|
||||
}
|
||||
const anchor = event.shiftKey ? view.state.selection.main.anchor : at;
|
||||
pick({ anchor, head: at });
|
||||
const win = host.ownerDocument.defaultView;
|
||||
const stop = () => {
|
||||
win.removeEventListener("mousemove", move);
|
||||
win.removeEventListener("mouseup", stop);
|
||||
};
|
||||
const move = (e) => {
|
||||
if (gone || !(e.buttons & 1)) return stop();
|
||||
pick({ anchor, head: where(e) });
|
||||
};
|
||||
win.addEventListener("mousemove", move);
|
||||
win.addEventListener("mouseup", stop);
|
||||
});
|
||||
if (off) host.classList.add("is-disabled");
|
||||
host.field = field;
|
||||
if (cm) build();
|
||||
|
||||
Reference in new issue
Block a user