From 1516b25ea3890fb3498a4ed8a5dfebccf2f4c0e1 Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Sat, 14 Nov 2026 10:42:23 -0800 Subject: [PATCH] Seed new notepad tabs with their name as a heading and focus under it, show Learning switch on/off as working right away, and stop the Tauri window from taking file drops AI Assisted --- plan2code-app/src-tauri/tauri.conf.json | 1 + scripts/test-web-console-notepad.mjs | 1 + scripts/test-web-console-page-notepad.mjs | 10 +++++-- .../public/activities/bounce-music.js | 2 +- src/web-console/public/notepad-editor.js | 9 +++++- src/web-console/public/screens/dashboard.js | 10 +++++++ .../public/screens/learning-row.js | 30 ++++++++++++++++++- src/web-console/public/screens/notepad.js | 6 +++- src/web-console/public/styles/learning.css | 4 +++ src/web-console/routes.mjs | 9 +++++- 10 files changed, 75 insertions(+), 7 deletions(-) diff --git a/plan2code-app/src-tauri/tauri.conf.json b/plan2code-app/src-tauri/tauri.conf.json index 239ac83..15fccd2 100644 --- a/plan2code-app/src-tauri/tauri.conf.json +++ b/plan2code-app/src-tauri/tauri.conf.json @@ -15,6 +15,7 @@ "width": 1280, "height": 800, "maximized": true, + "dragDropEnabled": false, "url": "index.html" } ], diff --git a/scripts/test-web-console-notepad.mjs b/scripts/test-web-console-notepad.mjs index cd9cae1..eb8f2a6 100644 --- a/scripts/test-web-console-notepad.mjs +++ b/scripts/test-web-console-notepad.mjs @@ -821,6 +821,7 @@ test("GET /notepad answers a two-tab notepad, one tab at a time, and refuses an assert.equal(a.ok, true); assert.match(a.id, store.TAB_ID_RE); assert.equal(a.name, "Ideas"); + assert.equal((await getJson(s, `/notepad?tab=${a.id}`)).body.tab.text, "## Ideas\n\n\n", "a tab made through the route opens with its name as a heading"); assert.equal((await s.send(`/notepad/text?tab=${a.id}`, { text: "about ideas" })).status, 200); assert.equal((await s.send(`/notepad/text?tab=${b.id}`, { text: "about chores" })).status, 200); const dflt = await getJson(s, "/notepad"); diff --git a/scripts/test-web-console-page-notepad.mjs b/scripts/test-web-console-page-notepad.mjs index f747574..6547575 100644 --- a/scripts/test-web-console-page-notepad.mjs +++ b/scripts/test-web-console-page-notepad.mjs @@ -510,8 +510,11 @@ test("New tab asks for a name, refuses a bad or duplicate one, and Escape backs await newTab(s, " Big ideas ", "Big ideas"); assert.deepEqual(await tabNames(s), ["Notes", "Big ideas"]); assert.deepEqual(await selectedName(s), ["Big ideas"]); - assert.equal(await docText(s), "", "the new tab starts empty"); + assert.equal(readNotepad(s.project, idOf(s, "Big ideas")).text, "## Big ideas\n\n\n", "the new tab opens with its name as a heading"); assert.equal(await input(s).getAttribute("aria-readonly"), null, "and can be typed in"); + // The editor has the focus, the caret under the heading and one blank line. + await s.page.keyboard.type("hello"); + await until(() => readNotepad(s.project, idOf(s, "Big ideas")).text === "## Big ideas\n\nhello\n\n", 4000); assert.deepEqual(listTabs(s.project).tabs.map((tab) => tab.name), ["Notes", "Big ideas"]); assert.deepEqual(await violations(), []); }); @@ -524,7 +527,10 @@ test("each tab keeps its own text and pictures, and switching never saves into t await newTab(s, "Ideas"); const notes = idOf(s, "Notes"); const ideas = idOf(s, "Ideas"); - await until(() => readNotepad(s.project, notes).text === "notes text", 4000); + // The new tab opens with its heading and the editor focused: clear it to start from empty. + await s.page.keyboard.press("Control+a"); + await s.page.keyboard.press("Delete"); + await until(() => readNotepad(s.project, notes).text === "notes text" && readNotepad(s.project, ideas).text === "", 4000); await typeInto(s, "ideas text"); // Switch at once, before the debounce: the text still goes to Ideas. await tabNamed(s, "Notes").click(); diff --git a/src/web-console/public/activities/bounce-music.js b/src/web-console/public/activities/bounce-music.js index 1b7c639..a6f03a8 100644 --- a/src/web-console/public/activities/bounce-music.js +++ b/src/web-console/public/activities/bounce-music.js @@ -86,7 +86,7 @@ const DRUM_TOKENS = { k: "k", s: "s", h: "h", o: "o", K: "kh", S: "sh", O: "ko", // The chips: a bass, a lead and an arpeggio voice each. const VIBRATO = { rate: 6, depth: 0.012, delay: 0.14 }; const KITS = { - // The triangle bass and thin squares of a grey home console. + // The triangle bass and thin squares of a gray home console. nes: { bass: { wave: "triangle", gain: 0.9, decay: 0.08, sustain: 0.55 }, lead: { wave: "pulse", duty: 0.25, gain: 0.3, decay: 0.07, sustain: 0.7, vibrato: VIBRATO }, diff --git a/src/web-console/public/notepad-editor.js b/src/web-console/public/notepad-editor.js index 4cd9bf0..4ec8599 100644 --- a/src/web-console/public/notepad-editor.js +++ b/src/web-console/public/notepad-editor.js @@ -226,7 +226,14 @@ export function makeCodeMirrorEditor(parent, { onChange, label }) { readOnly = Boolean(on); view.dispatch({ effects: access.reconfigure(accessOf(readOnly)) }); }, - focus: () => view.focus(), + // `at`, when given, is the caret's offset in the text. + focus(at) { + if (Number.isInteger(at)) { + const pos = Math.min(Math.max(at, 0), view.state.doc.length); + view.dispatch({ selection: { anchor: pos }, scrollIntoView: true }); + } + view.focus(); + }, destroy() { view.destroy(); host.remove(); diff --git a/src/web-console/public/screens/dashboard.js b/src/web-console/public/screens/dashboard.js index aacfc41..f63e876 100644 --- a/src/web-console/public/screens/dashboard.js +++ b/src/web-console/public/screens/dashboard.js @@ -1413,6 +1413,15 @@ function learningBanner(sc) { // lessons.mjs, rescans and posts the menu again. export async function sendLearning(what) { if (hooks.learningBlocked()) return; + // Switching on or off shows as working at once, before the agent answers. + const sc = scan(); + const from = sc && sc.learning && sc.learning.state; + if ((what === "switch-on" || what === "switch-off") && from) { + page.learningBusy = { what, from, at: Date.now() }; + redraw(); + // One redraw at the limit, so a switch the agent never answers stops spinning. + setTimeout(redraw, 30500); + } try { const res = await fetch("/submit", { method: "POST", @@ -1424,6 +1433,7 @@ export async function sendLearning(what) { page.pendingResult = true; saveNow(); } catch (err) { + page.learningBusy = null; if (err && err.pending) page.pendingResult = true; hooks.banner( err && err.pending diff --git a/src/web-console/public/screens/learning-row.js b/src/web-console/public/screens/learning-row.js index 7bba644..c5d13ad 100644 --- a/src/web-console/public/screens/learning-row.js +++ b/src/web-console/public/screens/learning-row.js @@ -48,6 +48,25 @@ export function learningBlocked() { return ""; } +// How long a switch on or off may show as working before the row gives up +// waiting for the new state (the agent normally answers in a second or two). +const BUSY_MS = 30000; + +/** + * The switch the person just pressed while the agent works on it, or null. + * sendLearning() sets page.learningBusy the instant a switch is pressed; + * it ends when the scan shows a different state, the send fails, or BUSY_MS pass. + */ +function busySwitch(state) { + const busy = page.learningBusy; + if (!busy) return null; + if (busy.from !== state || Date.now() - busy.at > BUSY_MS) { + page.learningBusy = null; + return null; + } + return busy; +} + function agentButton(text, cls, what) { const b = el("button", cls, text); b.type = "button"; @@ -342,7 +361,16 @@ export function renderLearningRow(scan, position) { const pill = PILLS[state]; line.appendChild(el("span", "learn-pill" + pill.cls, pill.text)); const controls = el("span", "learn-controls"); - if (state === "not-set-up") { + const busy = busySwitch(state); + if (busy) { + row.classList.add("is-busy"); + row.setAttribute("aria-busy", "true"); + const working = el("span", "learn-busy"); + working.setAttribute("role", "status"); + working.append(el("span", "spinner tiny"), document.createTextNode(busy.what === "switch-on" ? "Switching on…" : "Switching off…")); + line.appendChild(el("span", "learn-say", busy.what === "switch-on" ? "Switching Learning on for this project." : "Switching Learning off for this project.")); + controls.appendChild(working); + } else if (state === "not-set-up") { line.appendChild(el("span", "learn-say", "Plan2Code can keep lessons about this codebase, approved by you.")); controls.appendChild(agentButton("Switch on", "btn small primary", "switch-on")); } else if (state === "off") { diff --git a/src/web-console/public/screens/notepad.js b/src/web-console/public/screens/notepad.js index c47c0e8..e8925b8 100644 --- a/src/web-console/public/screens/notepad.js +++ b/src/web-console/public/screens/notepad.js @@ -445,7 +445,11 @@ async function createNamed(name) { busy = false; tell(""); inform(""); - if (await showTab(id, false)) tabBar.focusTab(activeId); + if (!(await showTab(id, false))) return; + // The server seeded `## ` and blank lines: start typing under the heading. + const text = editor.getValue(); + if (text.startsWith("## ")) editor.focus(text.indexOf("\n") + 2); + else tabBar.focusTab(activeId); } async function renameTo(name) { diff --git a/src/web-console/public/styles/learning.css b/src/web-console/public/styles/learning.css index fd9259f..7c4391e 100644 --- a/src/web-console/public/styles/learning.css +++ b/src/web-console/public/styles/learning.css @@ -196,3 +196,7 @@ /* Review from the dashboard: the same card in a dialog over the menu. */ .modal.lessons-dialog { width: min(720px, calc(100vw - 32px)); } .lessons-dialog .card { margin: 0; box-shadow: none; border: 0; padding: 0; } + +/* Switching Learning on or off: shown the moment the button is pressed. */ +.learn-busy { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-3); } +.learn-row.is-busy .learn-pill { opacity: 0.6; } diff --git a/src/web-console/routes.mjs b/src/web-console/routes.mjs index 15f0d64..176633b 100644 --- a/src/web-console/routes.mjs +++ b/src/web-console/routes.mjs @@ -1208,7 +1208,14 @@ function notepadTabRoute(act) { // Declarations, not consts: ROUTES above names them before this line runs. function notepadTabNew(req, res, ctx) { - return notepadTabRoute((root, body) => createTab(root, body.name))(req, res, ctx); + return notepadTabRoute((root, body) => { + const made = createTab(root, body.name); + // The new tab opens with its own name as a heading; a failed seed leaves it empty. + try { + saveNote(root, made.id, `## ${made.name}\n\n\n`); + } catch {} + return made; + })(req, res, ctx); } function notepadTabRename(req, res, ctx) { return notepadTabRoute((root, body) => renameTab(root, body.id, body.name))(req, res, ctx);