read text aloud
This commit is contained in:
@@ -41,8 +41,13 @@ public enum ContextAction: Sendable, Equatable {
|
||||
case delete(String, isDirectory: Bool)
|
||||
case copyTerminalSelection(TerminalKind)
|
||||
case pasteIntoTerminal(TerminalKind)
|
||||
/// Inserts `/wait-what` with the pane's selection into the agent composer.
|
||||
case waitWhat(TerminalKind)
|
||||
/// Inserts `/bouwen <name>` into the agent composer for an ontwikkeling folder.
|
||||
case bouwen(String)
|
||||
/// Reads a Markdown file's prose aloud.
|
||||
case readAloudFile(String)
|
||||
case readAloudText(String)
|
||||
|
||||
/// Destructive items read in amber-deep.
|
||||
public var isDestructive: Bool {
|
||||
@@ -81,14 +86,14 @@ public enum ContextActions {
|
||||
return [
|
||||
.action(.passOnReference(ref, code: hasCode ? code : nil), label: hasCode ? "Pass on selection" : "Pass on reference"),
|
||||
.action(.copyReference(ref), label: "Copy reference"),
|
||||
] + showDiff
|
||||
] + (hasCode ? readAloudSelection(code ?? "", path: reference.path) : []) + showDiff
|
||||
case .projectRoot:
|
||||
return [
|
||||
.action(.newFile(inDirectory: ""), label: "New file"),
|
||||
.action(.revealInFinder(""), label: "Show in Finder"),
|
||||
]
|
||||
case let .file(path):
|
||||
return fileHead(path) + [
|
||||
return fileHead(path) + readAloudFile(path) + [
|
||||
.separator,
|
||||
.action(.rename(path, isDirectory: false), label: "Rename file"),
|
||||
.action(.revealInFinder(path), label: "Show in Finder"),
|
||||
@@ -109,10 +114,12 @@ public enum ContextActions {
|
||||
.action(.delete(path, isDirectory: true), label: "Delete folder"),
|
||||
]
|
||||
case let .terminal(kind, hasSelection):
|
||||
let waitWhat: [ContextMenuEntry] = hasSelection && kind == .agent
|
||||
? [.separator, .action(.waitWhat(kind), label: "Wait what?")] : []
|
||||
return (hasSelection ? [.action(.copyTerminalSelection(kind), label: "Copy")] : [])
|
||||
+ [.action(.pasteIntoTerminal(kind), label: "Paste")]
|
||||
+ [.action(.pasteIntoTerminal(kind), label: "Paste")] + waitWhat
|
||||
case let .gitRow(path, staged):
|
||||
return fileHead(path) + [
|
||||
return fileHead(path) + readAloudFile(path) + [
|
||||
.separator,
|
||||
staged ? .action(.unstage(path), label: "Unstage changes") : .action(.stage(path), label: "Stage changes"),
|
||||
.action(.openDiff(path), label: "Open diff"),
|
||||
@@ -128,6 +135,16 @@ public enum ContextActions {
|
||||
return String(parts[1])
|
||||
}
|
||||
|
||||
private static func readAloudFile(_ path: String) -> [ContextMenuEntry] {
|
||||
FileType.isMarkdown(path) ? [.separator, .action(.readAloudFile(path), label: "Read aloud")] : []
|
||||
}
|
||||
|
||||
/// Selected Markdown is read as prose; a selection with no prose left, such as one code block, is read as it is.
|
||||
private static func readAloudSelection(_ code: String, path: String) -> [ContextMenuEntry] {
|
||||
let prose = FileType.isMarkdown(path) ? MarkdownSpeech.plainText(MarkdownParser.parse(code)) : ""
|
||||
return [.separator, .action(.readAloudText(prose.isEmpty ? code : prose), label: "Read aloud selection")]
|
||||
}
|
||||
|
||||
private static func fileHead(_ path: String) -> [ContextMenuEntry] {
|
||||
let name = PathUtils.basename(path)
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user