updates plak menu item

This commit is contained in:
2026-10-28 16:18:03 +01:00
parent 92b90c0e13
commit 9bdda896af
13 changed files with 339 additions and 8 deletions
+15 -2
View File
@@ -41,6 +41,8 @@ public enum ContextAction: Sendable, Equatable {
case delete(String, isDirectory: Bool) case delete(String, isDirectory: Bool)
case copyTerminalSelection(TerminalKind) case copyTerminalSelection(TerminalKind)
case pasteIntoTerminal(TerminalKind) case pasteIntoTerminal(TerminalKind)
/// Reads the pane's selection aloud; the text is fetched when the item runs.
case readAloudTerminalSelection(TerminalKind)
/// Inserts `/wait-what` with the pane's selection into the agent composer. /// Inserts `/wait-what` with the pane's selection into the agent composer.
case waitWhat(TerminalKind) case waitWhat(TerminalKind)
/// Inserts `/bouwen <name>` into the agent composer for an ontwikkeling folder. /// Inserts `/bouwen <name>` into the agent composer for an ontwikkeling folder.
@@ -48,6 +50,10 @@ public enum ContextAction: Sendable, Equatable {
/// Reads a Markdown file's prose aloud. /// Reads a Markdown file's prose aloud.
case readAloudFile(String) case readAloudFile(String)
case readAloudText(String) case readAloudText(String)
/// Sends the editor selection to Plak as it is, code and all.
case plak(String)
/// Sends the pane's selection to Plak; the text is fetched when the item runs.
case plakTerminalSelection(TerminalKind)
/// Destructive items read in amber-deep. /// Destructive items read in amber-deep.
public var isDestructive: Bool { public var isDestructive: Bool {
@@ -86,7 +92,7 @@ public enum ContextActions {
return [ return [
.action(.passOnReference(ref, code: hasCode ? code : nil), label: hasCode ? "Pass on selection" : "Pass on reference"), .action(.passOnReference(ref, code: hasCode ? code : nil), label: hasCode ? "Pass on selection" : "Pass on reference"),
.action(.copyReference(ref), label: "Copy reference"), .action(.copyReference(ref), label: "Copy reference"),
] + (hasCode ? readAloudSelection(code ?? "", path: reference.path) : []) + showDiff ] + (hasCode ? readAloudSelection(code ?? "", path: reference.path) + plak(code ?? "") : []) + showDiff
case .projectRoot: case .projectRoot:
return [ return [
.action(.newFile(inDirectory: ""), label: "New file"), .action(.newFile(inDirectory: ""), label: "New file"),
@@ -114,10 +120,13 @@ public enum ContextActions {
.action(.delete(path, isDirectory: true), label: "Delete folder"), .action(.delete(path, isDirectory: true), label: "Delete folder"),
] ]
case let .terminal(kind, hasSelection): case let .terminal(kind, hasSelection):
let readAloud: [ContextMenuEntry] = hasSelection
? [.separator, .action(.readAloudTerminalSelection(kind), label: "Read aloud selection"),
.separator, .action(.plakTerminalSelection(kind), label: "Plak")] : []
let waitWhat: [ContextMenuEntry] = hasSelection && kind == .agent let waitWhat: [ContextMenuEntry] = hasSelection && kind == .agent
? [.separator, .action(.waitWhat(kind), label: "Wait what?")] : [] ? [.separator, .action(.waitWhat(kind), label: "Wait what?")] : []
return (hasSelection ? [.action(.copyTerminalSelection(kind), label: "Copy")] : []) return (hasSelection ? [.action(.copyTerminalSelection(kind), label: "Copy")] : [])
+ [.action(.pasteIntoTerminal(kind), label: "Paste")] + waitWhat + [.action(.pasteIntoTerminal(kind), label: "Paste")] + readAloud + waitWhat
case let .gitRow(path, staged): case let .gitRow(path, staged):
return fileHead(path) + readAloudFile(path) + [ return fileHead(path) + readAloudFile(path) + [
.separator, .separator,
@@ -145,6 +154,10 @@ public enum ContextActions {
return [.separator, .action(.readAloudText(prose.isEmpty ? code : prose), label: "Read aloud selection")] return [.separator, .action(.readAloudText(prose.isEmpty ? code : prose), label: "Read aloud selection")]
} }
private static func plak(_ code: String) -> [ContextMenuEntry] {
[.separator, .action(.plak(code), label: "Plak")]
}
private static func fileHead(_ path: String) -> [ContextMenuEntry] { private static func fileHead(_ path: String) -> [ContextMenuEntry] {
let name = PathUtils.basename(path) let name = PathUtils.basename(path)
return [ return [
+30
View File
@@ -0,0 +1,30 @@
import Foundation
/// The URL scheme of Plak, the scratchpad app: each send adds one block at the end of its page.
public enum Plak {
/// Text above this many UTF-8 bytes goes through the pasteboard, since a long URL can fail to open.
public static let appendLimit = 100_000
public static let pasteURL = URL(string: "plak://paste")!
public enum Delivery: Sendable, Equatable {
case append(URL)
case paste
}
/// URLComponents leaves `+` bare in a query, and Plak's contract asks for `%2B`.
public static func appendURL(_ text: String) -> URL? {
var components = URLComponents()
components.scheme = "plak"
components.host = "append"
components.queryItems = [URLQueryItem(name: "text", value: text)]
components.percentEncodedQuery = components.percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B")
return components.url
}
/// Nil when short text yields no URL.
public static func delivery(for text: String) -> Delivery? {
guard text.utf8.count <= appendLimit else { return .paste }
return appendURL(text).map(Delivery.append)
}
}
@@ -108,7 +108,8 @@ struct ContextMenuOverlay: View {
nonisolated static func tint(for action: ContextAction) -> MenuIconTint { nonisolated static func tint(for action: ContextAction) -> MenuIconTint {
switch action { switch action {
case .copyReference, .copyTerminalSelection, .pasteIntoTerminal, .readAloudFile, .readAloudText: .plain case .copyReference, .copyTerminalSelection, .pasteIntoTerminal, .readAloudFile, .readAloudText, .readAloudTerminalSelection,
.plak, .plakTerminalSelection: .plain
case .newFile, .newFolder, .stage: .add case .newFile, .newFolder, .stage: .add
case .copyFileName, .unstage, .revealInFinder: .modify case .copyFileName, .unstage, .revealInFinder: .modify
case .passOnReference, .passOnFileName, .bouwen, .waitWhat, .openDiff, .showDiff, .rename: .rename case .passOnReference, .passOnFileName, .bouwen, .waitWhat, .openDiff, .showDiff, .rename: .rename
@@ -121,7 +122,8 @@ struct ContextMenuOverlay: View {
case .passOnReference, .passOnFileName: ContextMenuRow.spark case .passOnReference, .passOnFileName: ContextMenuRow.spark
case .bouwen: "hammer" case .bouwen: "hammer"
case .waitWhat: "questionmark.bubble" case .waitWhat: "questionmark.bubble"
case .readAloudFile, .readAloudText: "speaker.wave.2" case .readAloudFile, .readAloudText, .readAloudTerminalSelection: "speaker.wave.2"
case .plak, .plakTerminalSelection: "note.text.badge.plus"
case .copyReference, .copyFileName, .copyTerminalSelection: "doc.on.doc" case .copyReference, .copyFileName, .copyTerminalSelection: "doc.on.doc"
case .pasteIntoTerminal: "doc.on.clipboard" case .pasteIntoTerminal: "doc.on.clipboard"
case .newFile: "doc.badge.plus" case .newFile: "doc.badge.plus"
@@ -10,6 +10,8 @@ public protocol SystemActing: AnyObject {
func copy(_ text: String) func copy(_ text: String)
func pasteboardText() -> String? func pasteboardText() -> String?
func revealInFinder(_ url: URL) func revealInFinder(_ url: URL)
/// Adds the text as a new block in Plak, which takes focus.
func sendToPlak(_ text: String)
/// Asked before a file with unsaved edits closes. /// Asked before a file with unsaved edits closes.
func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice
func openLog() func openLog()
@@ -45,6 +47,39 @@ public final class LiveSystemActions: SystemActing {
NSWorkspace.shared.activateFileViewerSelecting([url]) NSWorkspace.shared.activateFileViewerSelecting([url])
} }
public func sendToPlak(_ text: String) {
switch Plak.delivery(for: text) {
case let .append(url)?:
NSWorkspace.shared.open(url)
case .paste?:
pasteToPlak(text)
case nil:
Log.error("plak", "could not build the append URL")
}
}
/// Long text travels on the pasteboard; the user's own items return a second later,
/// unless something else was copied in that second.
private func pasteToPlak(_ text: String) {
let pasteboard = NSPasteboard.general
let saved = (pasteboard.pasteboardItems ?? []).map { item in
item.types.compactMap { type in item.data(forType: type).map { (type, $0) } }
}
copy(text)
let ours = pasteboard.changeCount
NSWorkspace.shared.open(Plak.pasteURL)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
guard pasteboard.changeCount == ours else { return }
pasteboard.clearContents()
guard !saved.isEmpty else { return }
pasteboard.writeObjects(saved.map { pairs in
let item = NSPasteboardItem()
for (type, data) in pairs { item.setData(data, forType: type) }
return item
})
}
}
public func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice { public func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice {
let alert = NSAlert() let alert = NSAlert()
alert.messageText = "Save changes to \(PathUtils.basename(path))?" alert.messageText = "Save changes to \(PathUtils.basename(path))?"
@@ -103,6 +103,14 @@ extension WorkspaceModel {
readAloud.read(text) readAloud.read(text)
case let .readAloudFile(path): case let .readAloudFile(path):
readAloudFile(path) readAloudFile(path)
case let .readAloudTerminalSelection(kind):
let text = terminal.selection(kind)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
let prose = MarkdownSpeech.plainText(MarkdownParser.parse(text))
if !readAloud.read(prose.isEmpty ? text : prose) { toasts.show("Nothing to read") }
case let .plak(text):
sendToPlak(text)
case let .plakTerminalSelection(kind):
sendToPlak(terminal.selection(kind) ?? "")
case let .newFile(directory): case let .newFile(directory):
overlay.present(.namePrompt(NamePromptRequest(purpose: .newFile(inDirectory: directory), anchor: anchor))) overlay.present(.namePrompt(NamePromptRequest(purpose: .newFile(inDirectory: directory), anchor: anchor)))
case let .newFolder(directory): case let .newFolder(directory):
@@ -137,6 +145,11 @@ extension WorkspaceModel {
} }
} }
private func sendToPlak(_ text: String) {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmed.isEmpty { toasts.show("Nothing to send") } else { app.system.sendToPlak(trimmed) }
}
/// The open file is read from its buffer, unsaved edits included; any other file from disk. /// The open file is read from its buffer, unsaved edits included; any other file from disk.
private func readAloudFile(_ path: String) { private func readAloudFile(_ path: String) {
let live = editor.flatMap { $0.activePath == path && $0.isLoaded(path) ? $0.text(for: path) : nil } let live = editor.flatMap { $0.activePath == path && $0.isLoaded(path) ? $0.text(for: path) : nil }
@@ -10,7 +10,7 @@ import Testing
} }
@Test func copyAppearsOnlyWithASelection() { @Test func copyAppearsOnlyWithASelection() {
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste", "Wait what?"]) #expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste", "Read aloud selection", "Plak", "Wait what?"])
#expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"]) #expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"])
} }
@@ -23,9 +23,25 @@ import Testing
#expect(ContextActions.entries(for: .terminal(.shell, hasSelection: true)) == [ #expect(ContextActions.entries(for: .terminal(.shell, hasSelection: true)) == [
.action(.copyTerminalSelection(.shell), label: "Copy"), .action(.copyTerminalSelection(.shell), label: "Copy"),
.action(.pasteIntoTerminal(.shell), label: "Paste"), .action(.pasteIntoTerminal(.shell), label: "Paste"),
.separator,
.action(.readAloudTerminalSelection(.shell), label: "Read aloud selection"),
.separator,
.action(.plakTerminalSelection(.shell), label: "Plak"),
]) ])
} }
@Test func plakAppearsOnlyWithASelectionInBothPanes() {
#expect(labels(.terminal(.agent, hasSelection: true)).contains("Plak"))
#expect(labels(.terminal(.shell, hasSelection: true)).contains("Plak"))
#expect(!labels(.terminal(.agent, hasSelection: false)).contains("Plak"))
#expect(!labels(.terminal(.shell, hasSelection: false)).contains("Plak"))
}
@Test func readAloudAppearsOnlyWithASelection() {
#expect(!labels(.terminal(.agent, hasSelection: false)).contains("Read aloud selection"))
#expect(!labels(.terminal(.shell, hasSelection: false)).contains("Read aloud selection"))
}
@Test func theMenuHasNoHeader() { @Test func theMenuHasNoHeader() {
#expect(ContextActions.header(for: .terminal(.agent, hasSelection: false), projectName: "app").isEmpty) #expect(ContextActions.header(for: .terminal(.agent, hasSelection: false), projectName: "app").isEmpty)
#expect(ContextActions.header(for: .directory(path: "src"), projectName: "app").isEmpty) #expect(ContextActions.header(for: .directory(path: "src"), projectName: "app").isEmpty)
@@ -123,6 +139,8 @@ import Testing
.separator, .separator,
.action(.readAloudText("$a = 1;"), label: "Read aloud selection"), .action(.readAloudText("$a = 1;"), label: "Read aloud selection"),
.separator, .separator,
.action(.plak("$a = 1;"), label: "Plak"),
.separator,
.action(.showDiff("src/a.php", line: 3), label: "Show diff"), .action(.showDiff("src/a.php", line: 3), label: "Show diff"),
]) ])
} }
@@ -143,3 +161,24 @@ import Testing
]) ])
} }
} }
@Suite struct PlakContextMenuTests {
private func plak(_ target: ContextTarget) -> [ContextMenuEntry] {
ContextActions.entries(for: target).filter { entry in
if case .action(.plak, _) = entry { true } else { false }
}
}
@Test func anEditorSelectionIsSentAsRawCode() {
let reference = AgentReference(path: "README.md", startLine: 1)
#expect(plak(.editor(reference: reference, code: "## Setup\nRun **this**")) == [
.action(.plak("## Setup\nRun **this**"), label: "Plak"),
])
}
@Test func noSelectionNoPlak() {
let reference = AgentReference(path: "src/a.php", startLine: 1)
#expect(plak(.editor(reference: reference, code: nil)).isEmpty)
#expect(plak(.editor(reference: reference, code: "")).isEmpty)
}
}
@@ -0,0 +1,35 @@
import Foundation
import HelderCore
import Testing
@Suite struct PlakTests {
private func query(_ text: String) -> String? {
Plak.appendURL(text)?.absoluteString.replacingOccurrences(of: "plak://append?text=", with: "")
}
@Test func spacesAndNewlinesArePercentEncoded() {
#expect(query("a b\nc") == "a%20b%0Ac")
}
@Test func ampersandPlusAndHashAreEncoded() {
#expect(query("a&b+c#d") == "a%26b%2Bc%23d")
}
@Test func theURLTargetsAppend() {
#expect(Plak.appendURL("x")?.absoluteString == "plak://append?text=x")
#expect(Plak.pasteURL.absoluteString == "plak://paste")
}
@Test func shortTextIsAppended() {
#expect(Plak.delivery(for: "hi") == .append(URL(string: "plak://append?text=hi")!))
#expect(Plak.delivery(for: String(repeating: "a", count: Plak.appendLimit)) != .paste)
}
@Test func textOverTheLimitGoesThroughThePasteboard() {
#expect(Plak.delivery(for: String(repeating: "a", count: Plak.appendLimit + 1)) == .paste)
}
@Test func theLimitCountsUTF8Bytes() {
#expect(Plak.delivery(for: String(repeating: "é", count: Plak.appendLimit / 2 + 1)) == .paste)
}
}
@@ -625,7 +625,7 @@ import Testing
Issue.record("no context menu") Issue.record("no context menu")
return return
} }
#expect(menuLabels(menu) == ["Copy", "Paste", "Wait what?"]) #expect(menuLabels(menu) == ["Copy", "Paste", "Read aloud selection", "Plak", "Wait what?"])
#expect(menu.header.isEmpty) #expect(menu.header.isEmpty)
#expect(menu.anchor == CGPoint(x: 900, y: 300)) #expect(menu.anchor == CGPoint(x: 900, y: 300))
} }
@@ -645,6 +645,68 @@ import Testing
#expect(harness.toastTitles == ["Passed to agent"]) #expect(harness.toastTitles == ["Passed to agent"])
} }
@Test func readAloudSelectionReadsTheSelectionAsProse() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " Run **npm test** first.\n"
await harness.perform(.context(.readAloudTerminalSelection(.agent)))
#expect(harness.speech.spoken == ["Run npm test first."])
#expect(harness.model.readAloud.isReading)
}
@Test func readAloudSelectionReadsTheShellSelection() async {
let harness = WorkspaceHarness()
let shell = FakeTerminal()
harness.model.terminal.attach(shell, as: .shell)
shell.selectedText = "```\nls -la\n```"
await harness.perform(.context(.readAloudTerminalSelection(.shell)))
#expect(harness.speech.spoken == ["```\nls -la\n```"])
}
@Test func readAloudSelectionWithBlankTextSaysSo() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " \n"
await harness.perform(.context(.readAloudTerminalSelection(.agent)))
#expect(harness.speech.spoken.isEmpty)
#expect(harness.toastTitles == ["Nothing to read"])
}
@Test func plakSendsTheTrimmedSelection() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " npm test\n"
await harness.perform(.context(.plakTerminalSelection(.agent)))
#expect(harness.system.plakked == ["npm test"])
}
@Test func plakSendsTheShellSelection() async {
let harness = WorkspaceHarness()
let shell = FakeTerminal()
harness.model.terminal.attach(shell, as: .shell)
shell.selectedText = "ls -la"
await harness.perform(.context(.plakTerminalSelection(.shell)))
#expect(harness.system.plakked == ["ls -la"])
}
@Test func plakWithBlankSelectionSaysSo() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " \n"
await harness.perform(.context(.plakTerminalSelection(.agent)))
#expect(harness.system.plakked.isEmpty)
#expect(harness.toastTitles == ["Nothing to send"])
}
@Test func plakSendsTheEditorSelection() async {
let harness = WorkspaceHarness()
await harness.perform(.context(.plak("\n $a = 1;\n")))
#expect(harness.system.plakked == ["$a = 1;"])
}
@Test func plakWithBlankEditorTextSaysSo() async {
let harness = WorkspaceHarness()
await harness.perform(.context(.plak(" \n ")))
#expect(harness.system.plakked.isEmpty)
#expect(harness.toastTitles == ["Nothing to send"])
}
@Test func pasteSendsThePasteboardToThatTerminal() async { @Test func pasteSendsThePasteboardToThatTerminal() async {
let harness = WorkspaceHarness() let harness = WorkspaceHarness()
let shell = FakeTerminal() let shell = FakeTerminal()
@@ -660,6 +722,12 @@ import Testing
#expect(ContextMenuOverlay.tint(for: .pasteIntoTerminal(.shell)) == .plain) #expect(ContextMenuOverlay.tint(for: .pasteIntoTerminal(.shell)) == .plain)
#expect(ContextMenuOverlay.symbol(for: .copyTerminalSelection(.agent)) == "doc.on.doc") #expect(ContextMenuOverlay.symbol(for: .copyTerminalSelection(.agent)) == "doc.on.doc")
#expect(ContextMenuOverlay.symbol(for: .pasteIntoTerminal(.agent)) == "doc.on.clipboard") #expect(ContextMenuOverlay.symbol(for: .pasteIntoTerminal(.agent)) == "doc.on.clipboard")
#expect(ContextMenuOverlay.tint(for: .readAloudTerminalSelection(.agent)) == .plain)
#expect(ContextMenuOverlay.symbol(for: .readAloudTerminalSelection(.shell)) == "speaker.wave.2")
#expect(ContextMenuOverlay.tint(for: .plakTerminalSelection(.agent)) == .plain)
#expect(ContextMenuOverlay.tint(for: .plak("x")) == .plain)
#expect(ContextMenuOverlay.symbol(for: .plakTerminalSelection(.shell)) == "note.text.badge.plus")
#expect(ContextMenuOverlay.symbol(for: .plak("x")) == "note.text.badge.plus")
} }
@Test func aProjectSwitchKeepsTheTerminalMenuWired() async { @Test func aProjectSwitchKeepsTheTerminalMenuWired() async {
@@ -10,6 +10,7 @@ final class FakeSystem: SystemActing {
var clipboard: String? var clipboard: String?
private(set) var copied: [String] = [] private(set) var copied: [String] = []
private(set) var revealed: [URL] = [] private(set) var revealed: [URL] = []
private(set) var plakked: [String] = []
private(set) var unsavedCloseQuestions: [String] = [] private(set) var unsavedCloseQuestions: [String] = []
/// Each `openNewInstance` call's folder; nil for the launcher. /// Each `openNewInstance` call's folder; nil for the launcher.
private(set) var newInstances: [URL?] = [] private(set) var newInstances: [URL?] = []
@@ -18,6 +19,7 @@ final class FakeSystem: SystemActing {
func copy(_ text: String) { copied.append(text) } func copy(_ text: String) { copied.append(text) }
func pasteboardText() -> String? { clipboard } func pasteboardText() -> String? { clipboard }
func revealInFinder(_ url: URL) { revealed.append(url) } func revealInFinder(_ url: URL) { revealed.append(url) }
func sendToPlak(_ text: String) { plakked.append(text) }
func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice { func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice {
unsavedCloseQuestions.append(path) unsavedCloseQuestions.append(path)
+12
View File
@@ -156,6 +156,8 @@ Right-clicking inside the code area, with or without a selection, shows a contex
With a selection, a separator and **Read aloud selection** follow Copy reference. It reads the selected text with the system voice; in a Markdown file the selection is read as prose, the markup left out. The rendered Markdown preview has no Read aloud selection; its selection is not Helder's (use Read aloud on the file). With a selection, a separator and **Read aloud selection** follow Copy reference. It reads the selected text with the system voice; in a Markdown file the selection is read as prose, the markup left out. The rendered Markdown preview has no Read aloud selection; its selection is not Helder's (use Read aloud on the file).
With a selection, a separator and **Plak** follow Read aloud selection. It sends the selected text to Plak, the user's scratchpad app; see [Plak](#plak). The preview has no Plak.
On a marked line of the live file (any marked line, blank lines and the space after the text included), a separator and a last item follow: **Show diff**, which opens the Diff centred on that line. A new file, Preview and the Diff's own menu have no Show diff. On a marked line of the live file (any marked line, blank lines and the space after the text included), a separator and a last item follow: **Show diff**, which opens the Diff centred on that line. A new file, Preview and the Diff's own menu have no Show diff.
### File-state behavior in the views ### File-state behavior in the views
@@ -197,6 +199,16 @@ The bottom pane of the fourth column.
- It behaves as a normal terminal for that shell. - It behaves as a normal terminal for that shell.
- It is one terminal only. There are no additional terminals in this version. - It is one terminal only. There are no additional terminals in this version.
### Right-click in a terminal
Right-clicking in the agent pane or the terminal pane shows a menu without a header line. With a selection it holds **Copy**, **Paste**, a separator, **Read aloud selection**, a separator and **Plak**; the agent pane adds a separator and **Wait what?**. Without a selection it holds only **Paste**.
**Read aloud selection** reads the selected text with the system voice, as prose with the Markdown markup left out. A selection with no prose left, such as one code block, is read as it is. Blank text reads nothing and shows the toast "Nothing to read".
### Plak
**Plak** (code and terminal menus, only with a selection) sends the selected text, trimmed, to Plak, the user's macOS scratchpad app. The text lands at the end of the Plak page as a new block; Plak opens (it starts if needed), scrolls to the block and takes the focus. Blank text sends nothing and shows the toast "Nothing to send". Text up to about 100 KB goes in the URL; longer text goes through the clipboard, and Helder restores the user's clipboard one second later. The URL contract is in [plak.md](plak.md).
--- ---
## 8. Status bar ## 8. Status bar
+20 -2
View File
@@ -26,7 +26,7 @@ Helder draws its own right-click menu, in the same dark style everywhere. This p
3. **Separator**: a thin line between groups of items. 3. **Separator**: a thin line between groups of items.
4. **Destructive item**: Discard and Delete read in amber-deep, so they stand out. 4. **Destructive item**: Discard and Delete read in amber-deep, so they stand out.
Each item has a small icon. Add-type items (Stage, New file, New folder) have a teal icon. Copy file name, Unstage and Show in Finder have an amber icon. Read aloud has a speaker icon. Each item has a small icon. Add-type items (Stage, New file, New folder) have a teal icon. Copy file name, Unstage and Show in Finder have an amber icon. Read aloud has a speaker icon. Plak has a note icon with a plus.
## Features ## Features
@@ -223,6 +223,8 @@ With a selection:
| # Copy reference | | # Copy reference |
|----------------------------------------| |----------------------------------------|
| )) Read aloud selection | | )) Read aloud selection |
|----------------------------------------|
| >> Plak |
+----------------------------------------+ +----------------------------------------+
``` ```
@@ -239,8 +241,9 @@ On a marked (teal) line of a changed file:
- **Pass on selection** passes the reference and the selected code. See [Pass on to Agent](pass-on-to-agent.md). - **Pass on selection** passes the reference and the selected code. See [Pass on to Agent](pass-on-to-agent.md).
- **Read aloud selection** reads the selected text aloud. In a Markdown file the markup is left out. Stop it with **Stop** in the [title bar](title-bar.md#read-aloud). - **Read aloud selection** reads the selected text aloud. In a Markdown file the markup is left out. Stop it with **Stop** in the [title bar](title-bar.md#read-aloud).
- **Plak** sends the selected text to [Plak](#plak). On a marked line it comes before Show diff.
- **Show diff** opens the full-screen [Diff](file-view-diff.md) of the file, centred on the line you right-clicked. Every marked line counts, a blank one and the space after the text included. A new file, where every line is marked, has no Show diff. A left click on a marked line only places the caret. - **Show diff** opens the full-screen [Diff](file-view-diff.md) of the file, centred on the line you right-clicked. Every marked line counts, a blank one and the space after the text included. A new file, where every line is marked, has no Show diff. A left click on a marked line only places the caret.
- The same menu shows on the rendered [Markdown preview](file-view-markdown.md) and on an image. There it refers to the file's first line, for example `README.md:1`, and has no Read aloud selection. To hear a previewed file, right-click it in the Explorer and choose **Read aloud**. - The same menu shows on the rendered [Markdown preview](file-view-markdown.md) and on an image. There it refers to the file's first line, for example `README.md:1`, and has no Read aloud selection and no Plak. To hear a previewed file, right-click it in the Explorer and choose **Read aloud**.
- `Cmd+Right` with code selected opens the Pass on prompt straight away, without the menu. - `Cmd+Right` with code selected opens the Pass on prompt straight away, without the menu.
### Diff ### Diff
@@ -269,6 +272,10 @@ With text selected in the pane:
| # Copy | | # Copy |
| # Paste | | # Paste |
|----------------------------------------| |----------------------------------------|
| )) Read aloud selection |
|----------------------------------------|
| >> Plak |
|----------------------------------------|
| ? Wait what? | | ? Wait what? |
+----------------------------------------+ +----------------------------------------+
``` ```
@@ -285,8 +292,19 @@ Without a selection:
- **Copy** (only with a selection): copies the selected terminal text. - **Copy** (only with a selection): copies the selected terminal text.
- **Paste**: types the clipboard text into that pane, as a normal paste would. With an empty clipboard nothing happens. - **Paste**: types the clipboard text into that pane, as a normal paste would. With an empty clipboard nothing happens.
- **Read aloud selection** (only with a selection): reads the selected text with the system voice. Markdown markup is left out. With nothing left to read, a [notification](notifications.md) says `Nothing to read`. Stop it with **Stop** in the [title bar](title-bar.md#read-aloud).
- **Plak** (only with a selection): sends the selected text to [Plak](#plak).
- **Wait what?** (Claude Code pane, only with a selection): inserts ``/wait-what `selected text` `` into the [Claude Code](claude-code.md) input, not sent. Spaces and blank lines around the selection are trimmed. A [notification](notifications.md) says `Passed to agent`. - **Wait what?** (Claude Code pane, only with a selection): inserts ``/wait-what `selected text` `` into the [Claude Code](claude-code.md) input, not sent. Spaces and blank lines around the selection are trimmed. A [notification](notifications.md) says `Passed to agent`.
### Plak
**Plak** sends the selected text to Plak, the scratchpad app for macOS. Plak must be installed.
- The text, with spaces and blank lines around it trimmed, goes to the end of the Plak page as a new block.
- Plak opens (it starts if it is not running), scrolls to the new block and takes the focus.
- A blank selection sends nothing. A [notification](notifications.md) says `Nothing to send`.
- A very long selection (more than about 100 KB) goes through the clipboard. Helder puts your own clipboard back one second later.
## Keyboard ## Keyboard
| Keys | Action | | Keys | Action |
+1
View File
@@ -4,3 +4,4 @@
- [Architecture](architecture.md): layers, folder map, commands, file ownership, gotchas. - [Architecture](architecture.md): layers, folder map, commands, file ownership, gotchas.
- [Design tokens](design/README.md): the visual source of truth (colours, type, geometry, screens). - [Design tokens](design/README.md): the visual source of truth (colours, type, geometry, screens).
- [Behaviour spec](behaviour.md): every panel and interaction. - [Behaviour spec](behaviour.md): every panel and interaction.
- [Plak URL scheme](plak.md): the `plak://` contract that the right-click Plak item relies on.
+63
View File
@@ -0,0 +1,63 @@
# Plak URL scheme
Plak is the user's scratchpad app for macOS. Other apps add text to it through two `plak://` URLs. This page is the contract that Helder relies on.
## `plak://append?text=<text>`
Adds the text at the end of the Plak page, as a new block with its own created date.
- Percent-encode the text as a URL query value: space `%20`, newline `%0A`, `&` `%26`, `+` `%2B`, `#` `%23`.
- Never encode a space as `+`. Plak keeps a `+` literal, so the block would show `+` signs.
- Plak detects the content type as for a paste. PHP, JSON, XML and CSV become a code block or a table. All other text becomes plain text.
## `plak://paste`
Adds the current contents of the macOS general pasteboard, text or images.
- Use it for images and for text over about 100 KB, where a long URL can fail to open.
- Put the content on the pasteboard first, then open the URL.
- Save the user's clipboard before, and restore it one second after.
## What Plak does
- Plak starts if it is not running. It shows its window, scrolled to the new content, and takes the focus.
- An empty or missing `text` adds nothing, but Plak still shows.
- Every other `plak://` URL does nothing.
- There is no callback and no error result. The sender cannot know if the add worked.
## Opening the URL
```sh
open "plak://append?text=Hello%20from%20my%20app"
```
```swift
var components = URLComponents()
components.scheme = "plak"
components.host = "append"
components.queryItems = [URLQueryItem(name: "text", value: text)]
// URLQueryItem leaves "+" as it is; encode it yourself.
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(of: "+", with: "%2B")
if let url = components.url { NSWorkspace.shared.open(url) }
```
```applescript
open location "plak://append?text=Hello%20from%20my%20app"
```
```js
shell.openExternal("plak://append?text=" + encodeURIComponent(text))
```
```python
subprocess.run(["open", "plak://append?text=" + urllib.parse.quote(text, safe="")])
```
## In Helder
- The **Plak** item in the right-click menu of the code and of both terminal panes uses this scheme. See [behaviour.md](behaviour.md#plak) and the [right-click guide](guide/right-click-menu.md#plak).
- URL building and the 100 KB choice: `Plak` in `Sources/HelderCore/Files/Plak.swift`. The limit counts UTF-8 bytes.
- Opening the URL and the clipboard save and restore: `SystemActing.sendToPlak` in `Sources/HelderUI/Shell/SystemActions.swift`.
Later, Plak will replace Helder's own notes (`.notes.txt`, `Cmd+N`; see [Notes](guide/notes.md)).