From 4964ff6eefb7cdfdd702097a61a1c221340e0bac Mon Sep 17 00:00:00 2001 From: Alvie Stoddard Date: Fri, 24 Jul 2026 12:36:05 -0700 Subject: [PATCH] Add contextual paste menu action --- Sources/Pesty/AppController.swift | 11 +++++++++++ Sources/Pesty/UI/ClipCardView.swift | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Sources/Pesty/AppController.swift b/Sources/Pesty/AppController.swift index 168016f..51b1084 100644 --- a/Sources/Pesty/AppController.swift +++ b/Sources/Pesty/AppController.swift @@ -23,6 +23,17 @@ final class AppController: NSObject, NSApplicationDelegate { var suppressAutoHide = false + /// Context-menu paste actions return to the app that was frontmost when + /// Pesty opened. Keep the wording contextual without implying an app will + /// be launched when that target is unavailable. + var pasteDestinationMenuTitle: String { + guard let previousApp, + !previousApp.isTerminated, + let name = previousApp.localizedName?.trimmingCharacters(in: .whitespacesAndNewlines), + !name.isEmpty else { return "Paste" } + return "Paste to \(name)" + } + func applicationDidFinishLaunching(_ notification: Notification) { NSApp.setActivationPolicy(.accessory) diff --git a/Sources/Pesty/UI/ClipCardView.swift b/Sources/Pesty/UI/ClipCardView.swift index 32ba404..a169224 100644 --- a/Sources/Pesty/UI/ClipCardView.swift +++ b/Sources/Pesty/UI/ClipCardView.swift @@ -237,9 +237,10 @@ struct ClipCardView: View { private var menu: some View { if let entry = pasteStackEntry { if entry.isPasted { + pasteToPreviousAppButton { AppController.shared.pasteItem(item) } Button("Re-add to Stack") { AppController.shared.reAddPasteStackEntry(entry) } } else { - Button("Paste") { AppController.shared.pasteStackEntry(entry) } + pasteToPreviousAppButton { AppController.shared.pasteStackEntry(entry) } } Button("Copy") { AppController.shared.copyItem(item) } Divider() @@ -247,7 +248,7 @@ struct ClipCardView: View { AppController.shared.removePasteStackEntry(entry) } } else { - Button("Paste") { AppController.shared.pasteItem(item) } + pasteToPreviousAppButton { AppController.shared.pasteItem(item) } Button("Copy") { AppController.shared.copyItem(item) } Divider() if !store.pinboards.isEmpty { @@ -274,6 +275,13 @@ struct ClipCardView: View { } } + private func pasteToPreviousAppButton(action: @escaping () -> Void) -> some View { + Button(action: action) { + Label(AppController.shared.pasteDestinationMenuTitle, + systemImage: "doc.on.clipboard") + } + } + private func selectCard() { if let entry = pasteStackEntry { AppController.shared.pasteSequence.select(entry)