# Scratchpad Scratchpad tabs for quick notes, like Zed's scratch buffers. Press `cmd-shift-n` and a new tab named "Scratchpad" opens in the shown space with an empty plain-text editor. Type anything: a to-do list, a command you keep retyping, something to paste to an agent later. The text keeps itself while the tab is open, even across a Herdr restart or update. Closing the tab is how you throw a note away. There are no files. ![Scratchpad](preview.png) ## What you see - **The tab:** named "Scratchpad" (rename it with `tab.rename`, `F2`), one mod pane filling it. - **The pane:** the theme's `background`, with an editor inset 6px left and right and 6px from the top. The editor has 13px text in your terminal font (`settings().font_family`), soft wrap on, and no line numbers or folding. The text is plain, with no syntax colors. - **A pane with no note** (one opened without `props.id`): the 13px `dim` line "No note here. Open a scratchpad tab with mod.open:scratchpad (cmd-shift-n)." with 12px padding. ## How it behaves - `cmd-shift-n` (from the included `keys.json`; `mod.open:scratchpad`) opens a new Scratchpad tab in the shown space and shows it. Every press is a new, empty note. - Click into the editor to type: the mod doesn't move the keyboard there. - Every change is saved at once. Restart Herdr, or let it update, and the tab comes back with its text. - Closing the tab discards the note: it is never shown again. - Several Scratchpad tabs can be open at once, in any spaces; each keeps its own text. Agent statuses play no part in this mod. ## Built from - One mod folder, `mods/scratchpad/`: `main.js` and `mod.json` (`{ "place": "none", "overlay": { "width": 1, "height": 1 } }`). - `main.js` default-exports one `View` with two roles, chosen by `props()`: - **Opened as an overlay** (`props().overlay` is set): the launcher. In `init` it calls `closeOverlay(props().overlay)`, then `run("tab.new", { name: "Scratchpad", space: , mod: "scratchpad", props: { id: } })`, and renders an empty `div()`. The new id is `Date.now().toString(36) + Math.random().toString(36).slice(2, 8)`. - **`{ id }`, a tab:** `EditorState.new({ value, font_family, font_size: 13, line_numbers: false, folding: false, soft_wrap: true })` drawn with `Editor.new(state)`. The value comes from `localStorage.getItem("note:" + id)`. On `state.on("change")` it calls `localStorage.setItem("note:" + id, state.value())`. `close()` sets it once more, awaits `localStorage.flush()` and releases the state. - `keys.json`: `{ "global": { "cmd-shift-n": "mod.open:scratchpad" } }`. - No programs, no network, no files outside Herdr's own storage. ## Watch out - A key binding passes the same arguments every time, so it can't give each new tab its own id. That is why the key opens the mod as a 1×1 overlay that makes the tab and closes itself, instead of calling `tab.new` directly. - The text survives restarts because Herdr keeps a mod copy's `localStorage` in a file named from its props (`data/scratchpad/store-.json`), and the props (`{ id }`) are saved with the tab. Two tabs opened with the same props share one store. Keep the id unique. - `close()` runs both when the tab closes and when Herdr quits, and it can't tell which. So it never deletes the text. A closed note's store file stays in `data/scratchpad/`: a few bytes, never shown, never pruned. - On Linux and Windows, bind `ctrl-shift-n` instead of `cmd-shift-n`. `cmd-shift-n` isn't used by Herdr's default keys on macOS (`cmd-n` makes a space); check yours before adding it. Merging the key turns `keys.json` into your own file, so Herdr won't add its new default keys to it on upgrade. - Herdr's `+` menu and tab bar can't list a mod without cloning `new-menu` and `tabs`, so this mod doesn't add itself there. See herdrdev/herdr-app#246 and #247. ## Done when - `herdr-app check ~/.config/herdr-app/mods/scratchpad` passes. - `herdr-app do mod.open '{"name":"scratchpad"}'` (or `cmd-shift-n`) opens a new "Scratchpad" tab in the shown space, with no overlay left open (`herdr-app status` shows `"overlays": []`). - Text typed into it is still there after quitting and reopening Herdr. - A second `cmd-shift-n` opens a second, empty Scratchpad tab, and the first keeps its text. - After closing a Scratchpad tab, the next `cmd-shift-n` opens an empty note, not the closed one's text.