From 086c735c65f07d4b297b8a1b1fa8a49e640cc6de Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Tue, 20 Oct 2026 12:01:37 -0700 Subject: [PATCH] Replace the Notebook tab toolbar with an x, a rename dialog and drag-only reordering AI Assisted --- .readme/web-console.md | 12 +- scripts/test-web-console-page-notepad.mjs | 128 +++++++++---------- src/web-console/public/index.html | 46 +++---- src/web-console/public/notepad-tabs.js | 37 ++++-- src/web-console/public/screens/notepad.js | 52 +++----- src/web-console/public/styles/notepad.css | 92 ++++++++----- src/web-console/public/styles/responsive.css | 9 +- 7 files changed, 194 insertions(+), 182 deletions(-) diff --git a/.readme/web-console.md b/.readme/web-console.md index 2e5eb6d..50f7b0f 100644 --- a/.readme/web-console.md +++ b/.readme/web-console.md @@ -419,12 +419,12 @@ working in. - **Tabs.** A row of named tabs sits across the top, each with its own text and its own pictures. **+ New tab** asks for a name first (1 to 40 characters, no - two the same in any case, up to 20 tabs). Under the row, **Rename** changes - the current tab's name (a double-click or **F2** on a tab does too), **Move - left** and **Move right** (or **Alt** with the arrow keys) reorder it, and - tabs can be dragged. The tab you left open is the one you come back to. - **Delete** asks twice and takes the tab's text and pictures with it; with no - tab left, the dialog asks you to make one. A notebook from before tabs opens + two the same in any case, up to 20 tabs), in a small dialog. There is no + toolbar under the row: a double-click (or **F2**) on a tab renames it, the **x** + beside its name deletes it (the **Delete** key does too), and tabs are moved + only by dragging them. The tab you left open is the one you come back to. + Delete opens a dialog that asks twice and takes the tab's text and pictures + with it; with no tab left, the dialog asks you to make one. A notebook from before tabs opens as one tab called **Notes**. - **Markdown, styled as you type.** The editor shows Markdown in place: headings grow, bullets draw, bold, code, quotes and links take their look, and diff --git a/scripts/test-web-console-page-notepad.mjs b/scripts/test-web-console-page-notepad.mjs index 8bfd7aa..db319a3 100644 --- a/scripts/test-web-console-page-notepad.mjs +++ b/scripts/test-web-console-page-notepad.mjs @@ -405,16 +405,19 @@ const tabNames = (s) => tabButtons(s).evaluateAll((bs) => bs.map((b) => b.textCo const selectedName = (s) => s.page.locator('#notepad-tabs .notepad-tab[aria-selected="true"]').evaluateAll((bs) => bs.map((b) => b.textContent)); const status = (s) => s.page.locator("#notepad-status").textContent(); const idOf = (s, name) => listTabs(s.project).tabs.find((tab) => tab.name === name)?.id; +// The x beside a tab's name: the current tab's, or the one named. +const X_SELECTED = '#notepad-tabs .notepad-tab[aria-selected="true"] + .notepad-tab-x'; +const xOf = (s, name) => s.page.locator(`#notepad-tabs .notepad-tab-x[aria-label="Delete ${name}"]`); const nameError = (s) => s.page.locator("#notepad-name-error").textContent(); // Makes a tab through the page: the button, the name form, Enter. async function newTab(s, name, shown = name) { await s.page.click("#notepad-tab-new"); - await s.page.locator("#notepad-name-form:not([hidden])").waitFor(); + await s.page.locator("#notepad-name-dlg[open]").waitFor(); await s.page.fill("#notepad-name", name); await s.page.keyboard.press("Enter"); await s.page.waitForFunction((n) => [...document.querySelectorAll("#notepad-tabs .notepad-tab")].some((b) => b.textContent === n && b.getAttribute("aria-selected") === "true"), shown); - await s.page.waitForFunction(() => document.getElementById("notepad-name-form").hidden); + await s.page.waitForFunction(() => !document.getElementById("notepad-name-dlg").open); } // A notepad in its first shape: meta.json v1, note.md and images/ at the top. @@ -455,7 +458,7 @@ test("New tab asks for a name, refuses a bad or duplicate one, and Escape backs const violations = await watchViolations(s); await openNotepad(s); await s.page.click("#notepad-tab-new"); - await s.page.locator("#notepad-name-form:not([hidden])").waitFor(); + await s.page.locator("#notepad-name-dlg[open]").waitFor(); assert.equal(await s.page.locator("#notepad-name-label").textContent(), "Name this tab"); assert.equal(await s.page.evaluate(() => document.activeElement.id), "notepad-name", "the field has the focus"); assert.equal(await s.page.inputValue("#notepad-name"), ""); @@ -476,13 +479,13 @@ test("New tab asks for a name, refuses a bad or duplicate one, and Escape backs // Escape closes the form, not the Notebook, and gives the focus back. await s.page.keyboard.press("Escape"); - await s.page.waitForFunction(() => document.getElementById("notepad-name-form").hidden); + await s.page.waitForFunction(() => !document.getElementById("notepad-name-dlg").open); assert.equal(await s.page.evaluate(() => document.getElementById("notepad-modal").open), true); assert.equal(await s.page.evaluate(() => document.activeElement.id), "notepad-tab-new"); // Cancel does the same. await s.page.click("#notepad-tab-new"); await s.page.click("#notepad-name-cancel"); - await s.page.waitForFunction(() => document.getElementById("notepad-name-form").hidden); + await s.page.waitForFunction(() => !document.getElementById("notepad-name-dlg").open); await newTab(s, " Big ideas ", "Big ideas"); assert.deepEqual(await tabNames(s), ["Notes", "Big ideas"]); @@ -559,27 +562,28 @@ test("each tab keeps its own text and pictures, and switching never saves into t assert.deepEqual(await violations(), []); }); -test("Rename opens the same form with the name selected; F2 and double-click work too", async (t) => { +test("Double-click opens the rename modal with the name selected; F2 works too, and there is no Rename button", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); await openNotepad(s); await newTab(s, "Ideas"); const ideas = idOf(s, "Ideas"); - await s.page.click("#notepad-tab-rename"); - await s.page.locator("#notepad-name-form:not([hidden])").waitFor(); + assert.equal(await s.page.locator("#notepad-tab-rename, #notepad-tab-tools").count(), 0, "the bottom toolbar is gone"); + await tabNamed(s, "Ideas").dblclick(); + await s.page.locator("#notepad-name-dlg[open]").waitFor(); assert.equal(await s.page.locator("#notepad-name-label").textContent(), "Rename this tab"); assert.equal(await s.page.inputValue("#notepad-name"), "Ideas"); assert.equal(await s.page.evaluate(() => document.getElementById("notepad-name").selectionEnd - document.getElementById("notepad-name").selectionStart), 5, "the name is selected"); // Its own name is not a duplicate; another tab's is. await s.page.keyboard.press("Enter"); - await s.page.waitForFunction(() => document.getElementById("notepad-name-form").hidden); - await s.page.click("#notepad-tab-rename"); + await s.page.waitForFunction(() => !document.getElementById("notepad-name-dlg").open); + await tabNamed(s, "Ideas").dblclick(); await s.page.fill("#notepad-name", "notes"); await s.page.keyboard.press("Enter"); assert.equal(await nameError(s), errorSentence("duplicate-name")); await s.page.fill("#notepad-name", "Plans"); await s.page.keyboard.press("Enter"); - await s.page.waitForFunction(() => document.getElementById("notepad-name-form").hidden); + await s.page.waitForFunction(() => !document.getElementById("notepad-name-dlg").open); assert.deepEqual(await tabNames(s), ["Notes", "Plans"]); assert.equal(listTabs(s.project).tabs.find((tab) => tab.id === ideas).name, "Plans"); assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Plans", "the focus is back on the tab"); @@ -587,11 +591,11 @@ test("Rename opens the same form with the name selected; F2 and double-click wor // F2 on a focused tab, and a double-click. await tabNamed(s, "Plans").focus(); await s.page.keyboard.press("F2"); - await s.page.locator("#notepad-name-form:not([hidden])").waitFor(); + await s.page.locator("#notepad-name-dlg[open]").waitFor(); assert.equal(await s.page.inputValue("#notepad-name"), "Plans"); await s.page.keyboard.press("Escape"); await tabNamed(s, "Notes").dblclick(); - await s.page.locator("#notepad-name-form:not([hidden])").waitFor(); + await s.page.locator("#notepad-name-dlg[open]").waitFor(); assert.equal(await s.page.inputValue("#notepad-name"), "Notes"); assert.deepEqual(await selectedName(s), ["Notes"], "double-click picked the tab it renames"); }); @@ -617,42 +621,29 @@ const drag = (s, from, to, { kind = "tab" } = {}) => { from, to, kind }, ); -test("tabs reorder by drag and by keyboard, and the order is kept", async (t) => { +test("tabs reorder by drag only, and the order is kept", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); await openNotepad(s); for (const name of ["Ideas", "Plans", "Done"]) await newTab(s, name); assert.deepEqual(await tabNames(s), ["Notes", "Ideas", "Plans", "Done"]); const order = () => listTabs(s.project).tabs.map((tab) => tab.name); - // Keyboard: Alt+Left and Alt+Right on a focused tab, focus stays on it. + // No buttons and no Alt+Arrow: a drag is the only way to move a tab. + assert.equal(await s.page.locator("#notepad-tab-left, #notepad-tab-right").count(), 0); await tabNamed(s, "Done").focus(); await s.page.keyboard.press("Alt+ArrowLeft"); - await until(() => order().join() === "Notes,Ideas,Done,Plans", 4000); - assert.deepEqual(await tabNames(s), ["Notes", "Ideas", "Done", "Plans"]); - assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Done"); - assert.equal(await status(s), "Moved Done to position 3 of 4", "the move is announced"); - await s.page.keyboard.press("Alt+ArrowLeft"); - await s.page.keyboard.press("Alt+ArrowLeft"); - await s.page.keyboard.press("Alt+ArrowLeft"); - await until(() => order().join() === "Done,Notes,Ideas,Plans", 4000); - assert.equal(await status(s), "Moved Done to position 1 of 4", "and it stops at the first place"); - // Plain arrows move the focus without moving the tab. - await s.page.keyboard.press("ArrowRight"); - assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Notes"); - assert.equal(order().join(), "Done,Notes,Ideas,Plans"); - - // The visible buttons act on the current tab. - await tabNamed(s, "Plans").click(); - await s.page.click("#notepad-tab-left"); - await until(() => order().join() === "Done,Notes,Plans,Ideas", 4000); - await s.page.click("#notepad-tab-right"); - await until(() => order().join() === "Done,Notes,Ideas,Plans", 4000); - assert.equal(await s.page.locator("#notepad-tab-right").isDisabled(), true, "the last tab cannot move right"); + await s.page.waitForTimeout(300); + assert.equal(order().join(), "Notes,Ideas,Plans,Done", "Alt+Arrow moved nothing"); + // Arrows only move the focus, with or without Alt, and never the tab. + assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Plans"); + await s.page.keyboard.press("ArrowLeft"); + assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Ideas"); + assert.equal(order().join(), "Notes,Ideas,Plans,Done"); // Drag: the target shows a mark, the dragged tab lands just before it. - assert.equal(await drag(s, "Plans", "Done"), true, "the target is marked while dragged over"); - await until(() => order().join() === "Plans,Done,Notes,Ideas", 4000); - assert.deepEqual(await tabNames(s), ["Plans", "Done", "Notes", "Ideas"]); + assert.equal(await drag(s, "Done", "Notes"), true, "the target is marked while dragged over"); + await until(() => order().join() === "Done,Notes,Ideas,Plans", 4000); + assert.deepEqual(await tabNames(s), ["Done", "Notes", "Ideas", "Plans"]); assert.equal(await s.page.locator("#notepad-tabs .is-drop-before").count(), 0, "the mark is gone after the drop"); // Text dragged over a tab does nothing. @@ -660,14 +651,14 @@ test("tabs reorder by drag and by keyboard, and the order is kept", async (t) => s.page.on("request", (r) => r.url().includes("/notepad/tab/order") && posted.push(r.url())); assert.equal(await drag(s, "Plans", "Ideas", { kind: "text" }), false); await s.page.waitForTimeout(300); - assert.equal(order().join(), "Plans,Done,Notes,Ideas"); + assert.equal(order().join(), "Done,Notes,Ideas,Plans"); assert.equal(posted.length, 0); // Reopened, the order stands. await s.page.reload({ waitUntil: "domcontentloaded" }); await drawn(s.page); await openNotepad(s); - assert.deepEqual(await tabNames(s), ["Plans", "Done", "Notes", "Ideas"]); + assert.deepEqual(await tabNames(s), ["Done", "Notes", "Ideas", "Plans"]); }); test("Delete asks twice, Escape backs out of either, and only the second confirm removes the tab and its folder", async (t) => { @@ -688,7 +679,7 @@ test("Delete asks twice, Escape backs out of either, and only the second confirm const panel = s.page.locator("#notepad-delete"); const text = () => s.page.locator("#notepad-delete-text").textContent(); - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await panel.waitFor({ state: "visible" }); assert.equal(await text(), "This deletes the tab Ideas, its text and its 2 pictures. This cannot be undone."); assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Keep tab", "Keep tab has the focus"); @@ -700,7 +691,7 @@ test("Delete asks twice, Escape backs out of either, and only the second confirm assert.equal(await s.page.evaluate(() => document.activeElement.textContent), "Ideas"); // Step one then Escape: nothing deleted, and the Notebook stays open. - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await s.page.click("#notepad-delete-go"); assert.equal(await text(), "Really delete Ideas for good?"); assert.equal(await s.page.locator("#notepad-delete-go").textContent(), "Yes, delete it"); @@ -710,13 +701,13 @@ test("Delete asks twice, Escape backs out of either, and only the second confirm assert.equal(await s.page.evaluate(() => document.getElementById("notepad-modal").open), true); assert.equal(fs.existsSync(folder), true); // Escape at the first step too. - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await s.page.keyboard.press("Escape"); await panel.waitFor({ state: "hidden" }); assert.equal(fs.existsSync(folder), true); // Both confirms: gone, with its folder, and the neighbour is shown. - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await s.page.click("#notepad-delete-go"); await s.page.click("#notepad-delete-go"); await until(() => !fs.existsSync(folder), 4000); @@ -726,7 +717,7 @@ test("Delete asks twice, Escape backs out of either, and only the second confirm assert.equal(listTabs(s.project).last, idOf(s, "Notes"), "the neighbour became the last tab"); // Delete the last tab: the empty state, with the focus on its button. - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await s.page.click("#notepad-delete-go"); await s.page.click("#notepad-delete-go"); await s.page.locator("#notepad-empty").waitFor({ state: "visible" }); @@ -754,7 +745,7 @@ test("text typed into a tab that is then deleted is never saved, and a tab delet const saves = []; s.page.on("request", (r) => r.url().includes("/notepad/text") && saves.push(r.url())); await typeInto(s, "typed then deleted"); - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await s.page.click("#notepad-delete-go"); await s.page.click("#notepad-delete-go"); await s.page.waitForFunction(() => document.querySelectorAll("#notepad-tabs .notepad-tab").length === 1); @@ -772,31 +763,38 @@ test("text typed into a tab that is then deleted is never saved, and a tab delet assert.deepEqual(await tabNames(s), ["Notes"]); }); -test("a name form or delete question open on one tab closes when another tab is picked", async (t) => { +test("a double-click or an x acts on the tab it was made on, even when another is showing", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); await openNotepad(s); await newTab(s, "Ideas"); const notes = idOf(s, "Notes"); + assert.deepEqual(await selectedName(s), ["Ideas"]); - // Rename opened on Ideas, then Notes picked: the form goes, and Notes keeps its name. - await s.page.click("#notepad-tab-rename"); - await s.page.locator("#notepad-name-form:not([hidden])").waitFor(); - await tabNamed(s, "Notes").click(); - await s.page.waitForFunction(() => document.getElementById("notepad-name-form").hidden); + // Double-click on Notes while Ideas shows: Notes is picked and is the one renamed. + await tabNamed(s, "Notes").dblclick(); + await s.page.locator("#notepad-name-dlg[open]").waitFor(); + assert.equal(await s.page.inputValue("#notepad-name"), "Notes"); await until(async () => (await selectedName(s)).join() === "Notes", 4000); - assert.equal(listTabs(s.project).tabs.find((tab) => tab.id === notes).name, "Notes"); + await s.page.keyboard.press("Escape"); + await s.page.waitForFunction(() => !document.getElementById("notepad-name-dlg").open); + assert.equal(listTabs(s.project).tabs.find((tab) => tab.id === notes).name, "Notes", "Escape left the name alone"); - // Delete opened (and moved on to its second step) on Notes, then Ideas picked: the question goes. - await s.page.click("#notepad-tab-delete"); - await s.page.click("#notepad-delete-go"); - assert.equal(await s.page.locator("#notepad-delete-text").textContent(), "Really delete Notes for good?"); - await tabNamed(s, "Ideas").click(); - await s.page.locator("#notepad-delete").waitFor({ state: "hidden" }); - await until(async () => (await selectedName(s)).join() === "Ideas", 4000); - assert.deepEqual(await tabNames(s), ["Notes", "Ideas"], "nothing was deleted"); - // Asking again starts at the first step, naming the tab now open. - await s.page.click("#notepad-tab-delete"); + // The x on Ideas while Notes shows: the question names Ideas, and Keep leaves both. + await xOf(s, "Ideas").click(); + await s.page.locator("#notepad-delete").waitFor({ state: "visible" }); assert.match(await s.page.locator("#notepad-delete-text").textContent(), /^This deletes the tab Ideas,/); + await s.page.click("#notepad-delete-keep"); + await s.page.locator("#notepad-delete").waitFor({ state: "hidden" }); + assert.deepEqual(await tabNames(s), ["Notes", "Ideas"], "nothing was deleted"); + + // Both confirms on the x of the tab that is not showing now remove that one. + await tabNamed(s, "Notes").click(); + await until(async () => (await selectedName(s)).join() === "Notes", 4000); + await xOf(s, "Ideas").click(); + await s.page.click("#notepad-delete-go"); + await s.page.click("#notepad-delete-go"); + await s.page.waitForFunction(() => document.querySelectorAll("#notepad-tabs .notepad-tab").length === 1); + assert.deepEqual(await tabNames(s), ["Notes"]); }); test("when the tab after a delete cannot be loaded, the deleted text is not left on screen", async (t) => { @@ -809,7 +807,7 @@ test("when the tab after a delete cannot be loaded, the deleted text is not left await until(() => readNotepad(s.project, ideas).text === "doomed text", 4000); // The neighbour's read fails, as if the connection dropped right after the delete. await s.page.route("**/notepad?tab=*", (route) => route.abort()); - await s.page.click("#notepad-tab-delete"); + await s.page.click(X_SELECTED); await s.page.click("#notepad-delete-go"); await s.page.click("#notepad-delete-go"); await s.page.waitForFunction(() => document.querySelectorAll("#notepad-tabs .notepad-tab").length === 1); diff --git a/src/web-console/public/index.html b/src/web-console/public/index.html index 823cc3c..b7e0756 100644 --- a/src/web-console/public/index.html +++ b/src/web-console/public/index.html @@ -2615,28 +2615,6 @@
- - - + + +
+

Name this tab

+ +

+ +
+
+ + +

Delete this tab?

+

+ +
+ diff --git a/src/web-console/public/notepad-tabs.js b/src/web-console/public/notepad-tabs.js index 2035562..ad68304 100644 --- a/src/web-console/public/notepad-tabs.js +++ b/src/web-console/public/notepad-tabs.js @@ -1,11 +1,12 @@ // Plan2Code Web Console - the Notebook's tab bar. // // Draws #notepad-tabs from a list of { id, name } and tells screens/notepad.js -// what the person did: pick a tab (onSwitch), reorder with the keyboard or a -// drag, or ask to rename (onChange). No fetches here: the screen owns every -// request, and notepad.js owns the rules for order. +// what the person did: pick a tab (onSwitch), reorder with a drag, ask to +// rename (a double-click or F2) or ask to delete (the x beside the name, or the +// Delete key) (onChange). No fetches here: the screen owns every request, and +// notepad.js owns the rules for order. -import { dropTab, moveTab } from "./notepad.js"; +import { dropTab } from "./notepad.js"; import { el } from "./render.js"; const $ = (id) => document.getElementById(id); @@ -15,7 +16,7 @@ const DRAG_TYPE = "application/x-plan2code-notepad-tab"; /** * `onSwitch(id)` runs when a tab is picked. `onChange(event)` runs for * `{ type: "order", order, focus }` (a new order to save, focus the moved tab - * afterwards) and `{ type: "rename", id }`. + * afterwards), `{ type: "rename", id }` and `{ type: "delete", id }`. */ export function createTabs({ onSwitch, onChange }) { const bar = $("notepad-tabs"); @@ -25,6 +26,7 @@ export function createTabs({ onSwitch, onChange }) { // or text dragged over the bar does nothing. let dragging = null; + // The tab buttons; each sits in a wrapper with its x. const buttons = () => Array.from(bar.querySelectorAll(".notepad-tab")); const buttonFor = (id) => buttons().find((b) => b.dataset.id === id) || null; const ids = () => tabs.map((t) => t.id); @@ -43,7 +45,6 @@ export function createTabs({ onSwitch, onChange }) { const left = e.key === "ArrowLeft"; if (left || e.key === "ArrowRight") { e.preventDefault(); - if (e.altKey) return reorder(moveTab(ids(), id, left ? -1 : 1), id); const list = buttons(); const at = list.findIndex((b) => b.dataset.id === id); const next = list[Math.max(0, Math.min(list.length - 1, at + (left ? -1 : 1)))]; @@ -55,6 +56,9 @@ export function createTabs({ onSwitch, onChange }) { } else if (e.key === "F2") { e.preventDefault(); onChange({ type: "rename", id }); + } else if (e.key === "Delete") { + e.preventDefault(); + onChange({ type: "delete", id }); } } @@ -82,14 +86,25 @@ export function createTabs({ onSwitch, onChange }) { dragging = null; clearMarks(); }); - b.addEventListener("dragover", (e) => { + // The x is a button of its own beside the name, so the tab's text stays + // its name and a double-click or a drag on the name never reaches it. + const x = el("button", "notepad-tab-x", "×"); + x.type = "button"; + x.setAttribute("aria-label", "Delete " + tab.name); + x.title = "Delete tab"; + x.tabIndex = active ? 0 : -1; + x.addEventListener("click", () => onChange({ type: "delete", id: tab.id })); + const wrap = el("div", "notepad-tabwrap"); + wrap.setAttribute("role", "presentation"); + wrap.append(b, x); + wrap.addEventListener("dragover", (e) => { if (dragging === null) return; e.preventDefault(); e.dataTransfer.dropEffect = "move"; clearMarks(); if (tab.id !== dragging) b.classList.add("is-drop-before"); }); - b.addEventListener("drop", (e) => { + wrap.addEventListener("drop", (e) => { if (dragging === null) return; e.preventDefault(); e.stopPropagation(); @@ -98,7 +113,7 @@ export function createTabs({ onSwitch, onChange }) { clearMarks(); reorder(dropTab(ids(), id, tab.id), id); }); - return b; + return wrap; } // Dropping on the empty part of the bar moves the tab to the end. @@ -131,10 +146,6 @@ export function createTabs({ onSwitch, onChange }) { const empty = tabs.length === 0; $("notepad-empty").hidden = !empty; $("notepad-body").hidden = empty; - $("notepad-tab-tools").hidden = empty; - const at = tabs.findIndex((t) => t.id === activeId); - $("notepad-tab-left").disabled = at <= 0; - $("notepad-tab-right").disabled = at < 0 || at >= tabs.length - 1; // A long row scrolls the current tab into view. buttonFor(activeId)?.scrollIntoView?.({ block: "nearest", inline: "nearest" }); }, diff --git a/src/web-console/public/screens/notepad.js b/src/web-console/public/screens/notepad.js index 2555265..37b3585 100644 --- a/src/web-console/public/screens/notepad.js +++ b/src/web-console/public/screens/notepad.js @@ -21,7 +21,6 @@ import { cleanTabName, errorSentence, keepsText, - moveTab, nextDelete, nextSave, noteBytes, @@ -246,19 +245,10 @@ async function readNote(tab) { const nameOf = (id) => (tabs.find((t) => t.id === id) || {}).name || ""; -const ids = () => tabs.map((t) => t.id); - function drawTabs() { tabBar.draw(tabs, activeId); - const none = !activeId; - $("notepad-tab-rename").disabled = none || busy; - $("notepad-tab-delete").disabled = none || busy; $("notepad-tab-new").disabled = busy; $("notepad-empty-new").disabled = busy; - if (busy) { - $("notepad-tab-left").disabled = true; - $("notepad-tab-right").disabled = true; - } $("notepad-name-save").disabled = busy; } @@ -342,13 +332,6 @@ async function reorder(order, focus) { drawTabs(); } -// The current tab one place to the left or right. -function moveCurrent(delta) { - if (!activeId || busy) return; - const order = moveTab(ids(), activeId, delta); - if (order.join() !== ids().join()) reorder(order, activeId); -} - // A tab is no longer there (deleted here, or from another page): off the bar, // its unsaved text dropped without a save, and its neighbour on screen. async function gone(id, index = tabs.findIndex((t) => t.id === id), announce = true) { @@ -387,8 +370,8 @@ function openNameForm(mode) { closeDelete(); naming = mode; $("notepad-name-label").textContent = mode === "new" ? "Name this tab" : "Rename this tab"; - $("notepad-name-form").hidden = false; $("notepad-name-error").textContent = ""; + if (!$("notepad-name-dlg").open) $("notepad-name-dlg").showModal(); const input = $("notepad-name"); input.value = mode === "rename" ? nameOf(activeId) : ""; input.focus(); @@ -399,7 +382,7 @@ function closeNameForm(toFocus = true) { if (!naming) return; const was = naming; naming = null; - $("notepad-name-form").hidden = true; + $("notepad-name-dlg").close(); if (!toFocus) return; if (was === "rename") tabBar.focusTab(activeId); else (tabs.length ? $("notepad-tab-new") : $("notepad-empty-new")).focus(); @@ -456,8 +439,9 @@ async function submitName() { /* ------------------------------------------------------------ delete */ function paintDelete() { - $("notepad-delete").hidden = stage === "none"; - if (stage === "none") return; + const dlg = $("notepad-delete"); + if (stage === "none") return void (dlg.open && dlg.close()); + if (!dlg.open) dlg.showModal(); const name = nameOf(activeId); const count = images.filter((img) => img.id).length; const pics = count === 1 ? "1 picture" : `${count} pictures`; @@ -914,7 +898,7 @@ export async function openNotepad() { tell(""); inform(""); naming = null; - $("notepad-name-form").hidden = true; + $("notepad-name-dlg").close(); stage = "none"; paintDelete(); if (!dlg.open) dlg.showModal(); @@ -928,9 +912,12 @@ export function wireNotepad() { onSwitch: (id) => switchTo(id), onChange: async (event) => { if (event.type === "order") return reorder(event.order, event.focus); - // Rename acts on the current tab: a double-click or F2 on another one picks it first. + // Rename and delete act on the current tab: a double-click, F2 or x on + // another one picks it first. if (event.id && event.id !== activeId) await switchTo(event.id); - if (!event.id || event.id === activeId) openNameForm("rename"); + if (event.id && event.id !== activeId) return; + if (event.type === "delete") openDelete(); + else openNameForm("rename"); }, }); lightDismiss(dlg); @@ -940,10 +927,6 @@ export function wireNotepad() { $("notepad-close").addEventListener("click", () => dlg.close()); $("notepad-tab-new").addEventListener("click", () => openNameForm("new")); $("notepad-empty-new").addEventListener("click", () => openNameForm("new")); - $("notepad-tab-rename").addEventListener("click", () => openNameForm("rename")); - $("notepad-tab-left").addEventListener("click", () => moveCurrent(-1)); - $("notepad-tab-right").addEventListener("click", () => moveCurrent(1)); - $("notepad-tab-delete").addEventListener("click", openDelete); $("notepad-delete-keep").addEventListener("click", () => closeDelete(true)); $("notepad-delete-go").addEventListener("click", confirmDelete); $("notepad-name-cancel").addEventListener("click", () => closeNameForm()); @@ -951,15 +934,10 @@ export function wireNotepad() { e.preventDefault(); submitName(); }); - // Esc backs out of the name form or the delete question first, and only - // then closes the dialog. - dlg.addEventListener("keydown", (e) => { - if (e.key !== "Escape" || (!naming && stage === "none")) return; - e.preventDefault(); - e.stopPropagation(); - if (naming) closeNameForm(); - else closeDelete(true); - }); + // The two small dialogs are modal over the Notebook, so Esc (or any other + // way they close) backs out of them alone and the state follows the dialog. + $("notepad-name-dlg").addEventListener("close", () => closeNameForm()); + $("notepad-delete").addEventListener("close", () => closeDelete(true)); dlg.addEventListener("close", () => { flush(); $("btn-notepad").focus(); diff --git a/src/web-console/public/styles/notepad.css b/src/web-console/public/styles/notepad.css index 63384b7..7cd2154 100644 --- a/src/web-console/public/styles/notepad.css +++ b/src/web-console/public/styles/notepad.css @@ -38,7 +38,7 @@ flex: 1 1 auto; min-height: 0; border: 1px solid var(--rule-2); - border-radius: 8px; + border-radius: 0; overflow: hidden; background: var(--panel); } @@ -165,18 +165,35 @@ .notepad-status { margin: 0 auto 0 0; min-height: 1.4em; font-size: 12.5px; color: var(--ink-3); } .notepad-status.is-problem { color: var(--warn); } -/* The tab bar: a scrolling row of tab buttons with the current one marked, - then New tab. The tools under it act on the current tab. */ -.notepad-tabbar { flex: none; display: flex; align-items: flex-end; gap: 8px; margin-bottom: 4px; } -.notepad-tabs { flex: 1 1 auto; min-width: 0; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; } -.notepad-tab { +/* The tab bar: a scrolling row of tabs, each its name and an x, with the + current one marked, then New tab. A double-click renames, the x deletes and + a drag moves; the questions open in the small dialogs below. */ +.notepad-tabbar { flex: none; display: flex; align-items: flex-end; gap: 8px; margin-bottom: -1px; position: relative; z-index: 1; } +.notepad-tabs { flex: 1 1 auto; min-width: 0; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 0; } +.notepad-tabwrap { flex: none; - max-width: 220px; - padding: 6px 12px; + max-width: 240px; + display: flex; + align-items: center; border: 1px solid var(--rule-2); border-radius: 8px 8px 0 0; background: var(--panel-2); color: var(--ink-2); +} +.notepad-tabwrap:hover { color: var(--accent); border-color: var(--accent-line); } +.notepad-tabwrap:has(.notepad-tab[aria-selected="true"]) { + background: var(--accent-soft); + border-color: var(--accent); + border-bottom-color: var(--panel); + color: var(--ink); +} +.notepad-tab { + flex: 0 1 auto; + min-width: 0; + padding: 6px 4px 6px 12px; + border: 0; + background: none; + color: inherit; font: inherit; font-size: 13px; line-height: 1.2; @@ -185,27 +202,37 @@ text-overflow: ellipsis; white-space: nowrap; } -.notepad-tab:hover { color: var(--accent); border-color: var(--accent-line); } -.notepad-tab[aria-selected="true"] { - background: var(--accent-soft); - border-color: var(--accent); - color: var(--ink); - font-weight: 600; +.notepad-tab[aria-selected="true"] { font-weight: 600; } +.notepad-tab-x { + flex: none; + width: 20px; + height: 20px; + margin-right: 6px; + padding: 0; + border: 0; + border-radius: 4px; + background: none; + color: inherit; + font: inherit; + font-size: 16px; + line-height: 1; + cursor: pointer; + opacity: 0.6; } +.notepad-tabwrap:hover .notepad-tab-x, +.notepad-tabwrap:has(.notepad-tab[aria-selected="true"]) .notepad-tab-x, +.notepad-tab-x:focus-visible { opacity: 1; } +.notepad-tab-x:hover { background: var(--panel); color: var(--warn); } .notepad-tab:focus-visible, +.notepad-tab-x:focus-visible, .notepad-tab-new:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } -.notepad-tab.is-dragging { opacity: 0.5; } -.notepad-tab.is-drop-before { box-shadow: -3px 0 0 0 var(--accent); } +.notepad-tabwrap:has(.is-dragging) { opacity: 0.5; } +.notepad-tabwrap:has(.is-drop-before) { box-shadow: -3px 0 0 0 var(--accent); } .notepad-tabs.is-drop-end { box-shadow: inset -3px 0 0 0 var(--accent); } -.notepad-tab-new { flex: none; margin-bottom: 2px; } -.notepad-tab-tools { flex: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; } -.notepad-tab-tools[hidden] { display: none; } -.notepad-tab-tools .btn.tiny { margin-bottom: 0; } +.notepad-tab-new { flex: none; margin-bottom: 4px; } -/* The name form (New tab and Rename) and the delete question sit between the - tools and the editor, in the dialog, never in a browser prompt. */ -.notepad-name-form, -.notepad-delete, +/* The name and delete questions: small dialogs over the Notebook, never a + browser prompt. The empty state sits where the editor would. */ .notepad-empty { flex: none; margin: 0 0 10px; @@ -214,14 +241,12 @@ border-radius: 8px; background: var(--panel-2); } -.notepad-name-form[hidden], -.notepad-delete[hidden], .notepad-empty[hidden] { display: none; } -.notepad-name-form label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; } -.notepad-name-row { display: flex; gap: 8px; align-items: center; } -.notepad-name-row input { - flex: 1 1 auto; - min-width: 0; +.modal.notepad-sub { width: min(420px, calc(100vw - 32px)); } +.modal.notepad-sub h2 { margin: 0 0 10px; } +.notepad-name-form input { + display: block; + width: 100%; padding: 6px 8px; border: 1px solid var(--rule-2); border-radius: 6px; @@ -229,12 +254,11 @@ color: var(--ink); font: inherit; } -.notepad-name-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; } +.notepad-name-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; } .notepad-name-error { min-height: 1.2em; margin: 6px 0 0; } .notepad-name-error:not(:empty) { color: var(--warn); } +.modal.notepad-delete { border-color: var(--warn); } .notepad-delete p { margin: 0 0 8px; } -.notepad-delete { border-color: var(--warn); } -.notepad-delete-row { display: flex; gap: 8px; } .notepad-empty { text-align: center; padding: 28px 12px; } .notepad-empty p { margin: 0 0 12px; color: var(--ink-2); } /* Editor and pictures together, so the empty state hides both at once. */ diff --git a/src/web-console/public/styles/responsive.css b/src/web-console/public/styles/responsive.css index f7191a8..a514d0e 100644 --- a/src/web-console/public/styles/responsive.css +++ b/src/web-console/public/styles/responsive.css @@ -64,11 +64,10 @@ .notepad-images { flex-direction: column; align-items: stretch; } .notepad-tabbar { flex-wrap: wrap; } .modal.notepad .notepad-tab-new, - .modal.notepad .notepad-tab-tools .btn, - .modal.notepad .notepad-name-row .btn, - .modal.notepad .notepad-delete-row .btn, - .notepad-tab { min-height: 44px; } - .notepad-name-row { flex-wrap: wrap; } + .modal.notepad-sub .modal-actions .btn, + .notepad-tab, + .notepad-tab-x { min-height: 44px; } + .notepad-tab-x { width: 32px; } .notepad-add { align-self: flex-start; } .notepad-thumb .notepad-thumb-delete { width: 30px; height: 30px; font-size: 18px; } .modal.notepad-preview[open] { grid-template-columns: 52px minmax(0, 1fr) 52px; }