Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ pgrep ClapApp), print hint to start the app.
trigger and pastes the expansion.
- UI lists are paged: fetch 100 rows, fetch more as selection/scroll nears the
end.
- Keys: ↑/↓ navigate, Enter copy+close(+paste), Esc close, ⌘F focus search,
- Keys: ↑/↓ navigate, Enter copy+close(+paste), ⌘Enter paste an image's OCR
text instead of the image, Esc close, ⌘F focus search,
⌘1–⌘4 tabs (Classic/Shell/Favs/Media), ⌘P pin, ⌘S or ⌘B favorite,
⌘D or ⌥⌫ delete (⌥⌫ yields to delete-word while editing a non-empty
search), ⌘R regex toggle (also the `.*` button). Hover selects a row;
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ Run in your terminal:
curl -fsSL https://raw.githubusercontent.com/spongycode/clap/main/install.sh | bash
```

This compiles release binaries, places `clap.app` in `/Applications/`, symlinks the `clap` CLI into your `$PATH`, and launches the app.
This downloads the latest release, verifies its checksum and code signature, installs `clap.app` into `/Applications` (or `~/Applications`), links the `clap` CLI onto your `$PATH`, and launches the app. It never uses `sudo`, and falls back to building from source when no compatible release exists.

Options (pass after `bash -s --`):

```bash
curl -fsSL https://raw.githubusercontent.com/spongycode/clap/main/install.sh | bash -s -- --version v0.4.0 # pin a release
curl -fsSL https://raw.githubusercontent.com/spongycode/clap/main/install.sh | bash -s -- --source # build from source
curl -fsSL https://raw.githubusercontent.com/spongycode/clap/main/install.sh | bash -s -- --uninstall # remove (keeps history)
```

Also available: `--app-dir`, `--bin-dir`, `--no-launch`, `--purge` (with `--uninstall`, deletes history). Run with `--help` for details.

---

Expand Down Expand Up @@ -114,6 +124,7 @@ Press **⌘⇧V** to open the panel (configurable in Settings to `⌘⇧B`, `⌘
| **Single Click** | Copy entry, close panel, and paste directly into active app |
| **↑ / ↓** | Navigate entries |
| **Enter** | Copy selected entry, close, and paste into active app |
| **⌘ Enter** | On an image, paste its extracted (OCR) text instead of the image |
| **⌘1 / ⌘2 / ⌘3 / ⌘4** | Switch tabs: **Classic (⌘1)** · **Shell (⌘2)** · **Favs (⌘3)** · **Media (⌘4)** |
| **⌘S** or **⌘B** | Toggle Favorite / Bookmark on selected entry (marked with ❤️) |
| **⌘P** | Pin / unpin selected entry (pinned items stick to top of Classic view) |
Expand Down
4 changes: 4 additions & 0 deletions Sources/ClapApp/Panel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ final class PanelController: NSObject, NSWindowDelegate {
let chars = event.charactersIgnoringModifiers ?? ""

if modifiers == .command {
if event.keyCode == 36 || event.keyCode == 76 { // ⌘↩ / ⌘ keypad enter
appState.copySelectedAsText()
return nil
}
if handleCommandKey(chars) { return nil }
return event
}
Expand Down
1 change: 1 addition & 0 deletions Sources/ClapApp/PreviewCards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
if let image {
Image(nsImage: image)
.resizable()
.aspectRatio(contentMode: .fit)

Check warning on line 353 in Sources/ClapApp/PreviewCards.swift

View workflow job for this annotation

GitHub Actions / Build, Test & Lint (macOS)

Prefer `scaledToFit()` or `scaledToFill()` over `aspectRatio(contentMode:)` with a constant content mode (legacy_swiftui_aspect_ratio)

Check warning on line 353 in Sources/ClapApp/PreviewCards.swift

View workflow job for this annotation

GitHub Actions / Build, Test & Lint (macOS)

Prefer `scaledToFit()` or `scaledToFill()` over `aspectRatio(contentMode:)` with a constant content mode (legacy_swiftui_aspect_ratio)
.clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
.overlay(
RoundedRectangle(cornerRadius: 6, style: .continuous)
Expand Down Expand Up @@ -384,6 +384,7 @@
}
.buttonStyle(.bordered)
.controlSize(.mini)
.help("Copy and paste the extracted text (⌘↩)")
}

Text(ocrText)
Expand Down
19 changes: 19 additions & 0 deletions Sources/ClapApp/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,25 @@ final class AppState: ObservableObject {
copy(entry)
}

/// ⌘↩: paste an image's recognized (OCR) text instead of the image.
/// Text and shell entries behave exactly like plain Enter.
func copySelectedAsText() {
guard let entry = selectedEntry else { return }
guard entry.type == .image else { copy(entry); return }
guard let text = Self.extractedText(of: entry) else {
showTransientError("No text found in this image")
return
}
copyTransformedText(text)
}

/// OCR text stored for an image entry, or nil when recognition found none.
nonisolated static func extractedText(of entry: ClipboardEntry) -> String? {
guard entry.type == .image, let text = entry.content,
!text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return nil }
return text
}

func togglePinSelected() {
guard let entry = selectedEntry else { return }
Task { @MainActor [weak self] in
Expand Down
24 changes: 24 additions & 0 deletions Tests/ClapAppTests/AppStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,27 @@ struct PanelFrameTests {
#expect(slideout.listFrame(of: window) == NSRect(x: 768, y: 200, width: 520, height: 500))
}
}

@Suite("⌘↩ extracted-text paste")
struct ExtractedTextTests {
private func entry(_ type: EntryType, _ content: String?) -> ClipboardEntry {
ClipboardEntry(id: 1, type: type, content: content, imagePath: type == .image ? "x.png" : nil,
imageFormat: type == .image ? "png" : nil, contentHash: "h", createdAt: Date(),
lastUsedAt: Date(), sizeBytes: 1, isPinned: false, isFavorite: false,
useCount: 1, sourceApp: nil)
}

@Test func imageWithOCRTextYieldsIt() {
#expect(AppState.extractedText(of: entry(.image, "Invoice #1042")) == "Invoice #1042")
}

@Test func imageWithoutUsableTextYieldsNil() {
#expect(AppState.extractedText(of: entry(.image, nil)) == nil)
#expect(AppState.extractedText(of: entry(.image, " \n ")) == nil)
}

@Test func nonImagesAreNotTreatedAsOCR() {
#expect(AppState.extractedText(of: entry(.text, "hello")) == nil)
#expect(AppState.extractedText(of: entry(.shell, "git status")) == nil)
}
}
Loading
Loading