From 775bb95d5f1d400a12a55e2d468f0c57215545fd Mon Sep 17 00:00:00 2001 From: Nathan Nutter Date: Thu, 17 Sep 2026 18:45:42 -0500 Subject: [PATCH] Add Zed/Herdr row actions with two-phase delete Rows offer trailing Z (open in Zed) and H (Herdr space) icons: H runs timber create --herdr for new rows and timber herdr space --new for existing ones, dismisses the panel, and posts a Herdr space created notification. Delete is two-phase: first click arms (red icon), second click removes; selection moves, filter edits, and refreshes disarm. --- Panel.qml | 162 +++++++++++++++++++++++++++++++++++-------- README.md | 19 +++-- TimberModel.js | 24 +++++++ tests/model.test.mjs | 73 ++++++++++++++++++- 4 files changed, 241 insertions(+), 37 deletions(-) diff --git a/Panel.qml b/Panel.qml index 778e8b4..3da6400 100644 --- a/Panel.qml +++ b/Panel.qml @@ -24,6 +24,15 @@ Panel { property bool cursorActive: false property string pendingPath: "" property bool repoFormOpen: false + // In-flight Herdr routing: createForHerdr marks a `timber create` + // run that must notify instead of opening in Zed, and + // pendingHerdrValue carries the name@repo for the success message. + property bool createForHerdr: false + property string pendingHerdrValue: "" + // Two-phase delete: the value (name@repo) whose delete icon is + // armed (red) and awaiting a second click; blank when nothing is + // armed. Monochrome icons are unarmed and only arm on click. + property string armedRemoveValue: "" // True while one of the `timber repo add` form fields owns keyboard // focus. The raw key handler below must let those keys through to the @@ -62,6 +71,7 @@ Panel { function refresh() { root.pendingPath = "" + root.armedRemoveValue = "" root.filterText = "" root.selectedIndex = 0 root.cursorActive = false @@ -126,6 +136,8 @@ Panel { } function rebuildDisplay() { + // Any list change (filter edit, fresh listing) disarms delete. + root.armedRemoveValue = "" var items = TimberModel.itemsForTerm(root.repos, root.worktrees, root.filterText) displayModel.clear() for (var i = 0; i < items.length; i++) { @@ -153,6 +165,11 @@ Panel { Util.execArgv([root.omarchyPath + "/bin/omarchy-notification-send", "-u", "critical", "--app-name", "Timber", "Timber " + subject + " failed", detail]) } + // Successes (Herdr space created) surface as a normal notification. + function notify(subject, detail) { + Util.execArgv([root.omarchyPath + "/bin/omarchy-notification-send", "--app-name", "Timber", "Timber " + subject, detail]) + } + function openRepoForm() { root.repoFormOpen = true repoUrlField.clear() @@ -190,22 +207,61 @@ Panel { var row = displayModel.get(index) if (row.kind !== "open") return if (removeProc.running) return + root.armedRemoveValue = "" removeProc.command = ["timber", "remove", row.value] removeProc.running = true } + // Two-phase delete: the first click only arms the row (its delete + // icon turns red); a second click while armed runs `timber remove`. + // Arming one row disarms any other. + function armOrRemoveIndex(index) { + if (index < 0 || index >= displayModel.count) return + var row = displayModel.get(index) + if (row.kind !== "open") return + if (removeProc.running) return + var step = TimberModel.armOrConfirmRemove(root.armedRemoveValue, row.value) + root.armedRemoveValue = step.armed + if (step.confirmed) root.removeIndex(index) + } + + // The row itself (click or Return) keeps the historical default: + // open in Zed. The H icon routes to Herdr instead. function activateIndex(index) { + root.openInZed(index) + } + + function openInZed(index) { if (index < 0 || index >= displayModel.count) return var row = displayModel.get(index) if (row.kind === "open") { root.openPath(row.path) } else { if (createProc.running) return - createProc.command = ["timber", "create", "--no-herdr", row.value] + createProc.command = ["timber"].concat(TimberModel.createArgs(row.value, false)) createProc.running = true } } + function openInHerdr(index) { + if (index < 0 || index >= displayModel.count) return + var row = displayModel.get(index) + if (row.kind === "open") { + if (herdrProc.running) return + root.pendingHerdrValue = row.value + herdrProc.command = ["timber"].concat(TimberModel.herdrSpaceArgs(row.value)) + herdrProc.running = true + root.close() + } else { + if (createProc.running) return + root.createForHerdr = true + root.pendingHerdrValue = row.value + createProc.command = ["timber"].concat(TimberModel.createArgs(row.value, true)) + createProc.running = true + root.close() + } + } + implicitWidth: button.implicitWidth implicitHeight: button.implicitHeight @@ -215,6 +271,10 @@ Panel { Qt.callLater(function() { filterField.forceActiveFocus() }) } + // Moving selection to another row disarms a pending delete, so an + // armed (red) icon can never trail behind navigation. + onSelectedIndexChanged: root.armedRemoveValue = "" + ListModel { id: displayModel } Process { @@ -230,11 +290,19 @@ Panel { onExited: function(code) { if (code === 0) { var path = String(createStdout.text || "").trim().split("\n").pop() || "" - if (path) { + if (root.createForHerdr) { + root.createForHerdr = false + var created = root.pendingHerdrValue + root.pendingHerdrValue = "" + root.notify("Herdr space created", created || path) + root.refresh() + } else if (path) { root.setFilter("") root.openPath(path) } else root.notifyFailure("worktree create", "reported no path") } else { + root.createForHerdr = false + root.pendingHerdrValue = "" var detail = String(createStderr.text || "").trim().split("\n").pop() || ("exit " + code) root.notifyFailure("worktree create", detail) } @@ -261,6 +329,28 @@ Panel { } } + Process { + id: herdrProc + stdout: StdioCollector { + id: herdrStdout + waitForEnd: true + } + stderr: StdioCollector { + id: herdrStderr + waitForEnd: true + } + onExited: function(code) { + var value = root.pendingHerdrValue + root.pendingHerdrValue = "" + if (code === 0) { + root.notify("Herdr space created", value) + } else { + var detail = String(herdrStderr.text || "").trim().split("\n").pop() || ("exit " + code) + root.notifyFailure("herdr space", detail) + } + } + } + Process { id: repoAddProc stdout: StdioCollector { @@ -566,7 +656,7 @@ Panel { textFormat: Text.PlainText anchors.fill: parent anchors.leftMargin: Style.space(12) - anchors.rightMargin: Style.space(40) + anchors.rightMargin: actionsRow.implicitWidth + Style.space(20) verticalAlignment: Text.AlignVCenter text: (row.kind === "create" ? "+ " : "") + row.value color: root.foreground @@ -591,39 +681,51 @@ Panel { } } - // Stacked after the row MouseArea so its press wins and the - // row does not also activate (open in Zed) underneath it. - Item { - visible: row.selected && row.kind === "open" + // Stacked after the row MouseArea so a press on one of + // these wins and the row does not also activate underneath. + // Z opens in Zed (creating first for `create` rows); H + // routes to Herdr instead and posts a notification rather + // than opening Zed. + Row { + id: actionsRow + visible: row.selected anchors.right: parent.right - anchors.top: parent.top - anchors.bottom: parent.bottom - // Same width as the header repo button so both glyphs share - // a right column in any theme. - width: repoAddButton.width - - Text { - textFormat: Text.PlainText - anchors.centerIn: parent - // nf-md-delete (U+F0159): the destructive-row glyph the - // first-party bluetooth panel uses for Forget. - text: "󰅙" - color: Color.urgent - font.family: root.fontFamily - font.pixelSize: Style.font.title + anchors.rightMargin: Style.space(8) + anchors.verticalCenter: parent.verticalCenter + spacing: Style.space(4) + + PanelActionButton { + // Single-letter marks stand in for the Zed/Herdr logos + // so the buttons render in any panel font. + iconText: "Z" + tooltipText: row.kind === "open" ? "Open in Zed" : "Create and open in Zed" + foreground: root.foreground + fontFamily: root.fontFamily + enabled: !createProc.running && !herdrProc.running + onClicked: root.openInZed(row.index) } - MouseArea { - id: removeMouse - anchors.fill: parent - cursorShape: Qt.PointingHandCursor - onClicked: root.removeIndex(row.index) + PanelActionButton { + iconText: "H" + tooltipText: row.kind === "open" ? "Open in Herdr" : "Create in Herdr" + foreground: root.foreground + fontFamily: root.fontFamily + enabled: !createProc.running && !herdrProc.running + onClicked: root.openInHerdr(row.index) } - PanelToolTip { - visible: removeMouse.containsMouse - text: "Remove " + row.value + PanelActionButton { + visible: row.kind === "open" + // nf-md-delete (U+F0159): the destructive-row glyph the + // first-party bluetooth panel uses for Forget. + // Monochrome until the first click arms it; red while + // armed, when a second click runs `timber remove`. + iconText: "󰅙" + tooltipText: (row.value === root.armedRemoveValue ? "Click again to remove " : "Remove ") + row.value + foreground: row.value === root.armedRemoveValue ? Color.urgent : root.foreground fontFamily: root.fontFamily + enabled: !removeProc.running + onClicked: root.armOrRemoveIndex(row.index) } } } diff --git a/README.md b/README.md index d0d93ac..7f8de40 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ Omarchy overlay plugin that fronts [`timber`](https://github.com/nnutter/timber) managed Git worktrees, mirroring `timber tui`: fuzzy-filter the existing -worktrees, type `name@repo` to create, `enter` to open in Zed. +worktrees, type `name@repo` to create, `enter` to open in Zed, or use +the trailing row icons to open in Zed (`Z`) or a Herdr space (`H`). ## Requirements @@ -36,12 +37,20 @@ omarchy-shell io.github.nnutter.omarchy-timber toggle Keys: the header is a quickfilter field — type to filter (`@` narrows to repos) with native cursor editing (`←` / `→`, `home` / `end`, `backspace`, `ctrl+u` to clear), `↓` / `↑` move, -`enter` open or create, `esc` clear then close. `tab` keeps the +`enter` open or create in Zed, `esc` clear then close. `tab` keeps the platform meaning of switching to the next panel. Creating runs `timber create --no-herdr name@repo` and opens the reported path in -Zed. Hover a worktree row for its `×`, which runs `timber remove` -(no `--force`); failures arrive only as a critical desktop -notification titled `Timber worktree failed`. +Zed. Each selected row also offers trailing icons: `Z` opens in Zed +(same as `enter`), while `H` routes to Herdr — on a `name@repo` row +it runs `timber create --herdr name@repo`, on an existing worktree it +runs `timber herdr space --new name@repo` — the panel dismisses and a +`Timber Herdr space created` notification confirms instead of opening +Zed. Existing worktree +rows carry a third icon, `×`, which deletes in two phases: the first +click only arms it (the icon turns red), the second click runs +`timber remove` (no `--force`). Moving selection to another row, +editing the filter, or refreshing disarms; failures arrive only as a +critical desktop notification titled `Timber worktree failed`. To register a new repo, click the repo icon (GitHub's octicon-repo) in the panel header. The form fronts `timber repo add`: enter the diff --git a/TimberModel.js b/TimberModel.js index 6905d17..5e8f625 100644 --- a/TimberModel.js +++ b/TimberModel.js @@ -126,6 +126,30 @@ function splitValue(value) { return { name: parts.before, repo: parts.after } } +// argv (after `timber`) for `timber create [--no-herdr|--herdr] +// `. withHerdr selects the `--herdr` variant, which also +// creates a Herdr workspace for the new worktree. +function createArgs(value, withHerdr) { + return ["create", withHerdr ? "--herdr" : "--no-herdr", String(value || "")] +} + +// argv (after `timber`) for `timber herdr space --new `, +// which sets up (and opens) a Herdr space for an existing worktree. +function herdrSpaceArgs(value) { + return ["herdr", "space", "--new", String(value || "")] +} + +// One two-phase delete step for `armedRemoveValue`. Clicking the +// armed row confirms the remove; clicking any other row arms it +// instead (disarming the previous one). A blank click changes +// nothing and never confirms. +function armOrConfirmRemove(armed, value) { + var v = String(value || "") + if (!v) return { armed: String(armed || ""), confirmed: false } + if (String(armed || "") === v) return { armed: "", confirmed: true } + return { armed: v, confirmed: false } +} + // argv (after `timber`) for `timber repo add // [--name ] [--alias ]`. Blank name/alias flags are omitted // and surrounding whitespace is trimmed; returns null when the URL is diff --git a/tests/model.test.mjs b/tests/model.test.mjs index 4a5ab9c..5767b0d 100644 --- a/tests/model.test.mjs +++ b/tests/model.test.mjs @@ -9,10 +9,17 @@ vm.createContext(sandbox); // TimberModel.js declares bare functions (QML import style), so export // them explicitly for the test context. vm.runInContext( - src + "\n;globalThis.__timberModel = { itemsForTerm, splitValue, repoAddArgs };", + src + "\n;globalThis.__timberModel = { itemsForTerm, splitValue, repoAddArgs, createArgs, herdrSpaceArgs, armOrConfirmRemove };", sandbox, ); -const { itemsForTerm, splitValue, repoAddArgs } = sandbox.__timberModel; +const { + itemsForTerm, + splitValue, + repoAddArgs, + createArgs, + herdrSpaceArgs, + armOrConfirmRemove, +} = sandbox.__timberModel; const repos = [{ name: "timber" }, { name: "persona" }]; const worktrees = [ @@ -107,6 +114,68 @@ describe("repoAddArgs", () => { }); }); +describe("createArgs", () => { + it("creates without Herdr by default", () => { + assert.deepEqual(Array.from(createArgs("newfeat@timber", false)), [ + "create", + "--no-herdr", + "newfeat@timber", + ]); + }); + + it("creates with a Herdr workspace when asked", () => { + assert.deepEqual(Array.from(createArgs("newfeat@timber", true)), [ + "create", + "--herdr", + "newfeat@timber", + ]); + }); +}); + +describe("herdrSpaceArgs", () => { + it("opens a new Herdr space for the worktree", () => { + assert.deepEqual(Array.from(herdrSpaceArgs("alpha@timber")), [ + "herdr", + "space", + "--new", + "alpha@timber", + ]); + }); +}); + +describe("armOrConfirmRemove", () => { + // Spread into this realm: the step is a vm-context object. + const step = (armed, value) => ({ ...armOrConfirmRemove(armed, value) }); + + it("arms on the first click without confirming", () => { + assert.deepEqual(step("", "alpha@timber"), { + armed: "alpha@timber", + confirmed: false, + }); + }); + + it("confirms and disarms on the second click", () => { + assert.deepEqual(step("alpha@timber", "alpha@timber"), { + armed: "", + confirmed: true, + }); + }); + + it("re-arms to another row instead of confirming", () => { + assert.deepEqual(step("alpha@timber", "beta@persona"), { + armed: "beta@persona", + confirmed: false, + }); + }); + + it("ignores a blank click without confirming", () => { + assert.deepEqual(step("alpha@timber", ""), { + armed: "alpha@timber", + confirmed: false, + }); + }); +}); + describe("splitValue", () => { it("splits on the last @ so slashes survive in names", () => { // Spread into this realm: splitValue returns a vm-context object.