From a771d6573522f3f4630160ef85db153556048720 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 30 Jun 2024 10:15:36 -0700 Subject: [PATCH] macos: start context-menu --- .../Sources/Ghostty/SurfaceView_AppKit.swift | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 47641875a..371d6330e 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -868,10 +868,26 @@ extension Ghostty { } override func menu(for event: NSEvent) -> NSMenu? { - Ghostty.logger.warning("menu: event!") - return nil - } + // We only support right-click menus + guard event.type == .rightMouseDown else { return nil } + + // We need a surface + guard let surface = self.surface else { return nil } + + let menu = NSMenu() + + // If we have a selection, add copy + if ghostty_surface_has_selection(surface) { + menu.addItem(withTitle: "Copy", action: #selector(copy(_:)), keyEquivalent: "") + } + menu.addItem(withTitle: "Paste", action: #selector(paste(_:)), keyEquivalent: "") + + menu.addItem(NSMenuItem.separator()) + menu.addItem(withTitle: "Toggle Terminal Inspector", action: #selector(TerminalController.toggleTerminalInspector(_:)), keyEquivalent: "") + return menu + } + // MARK: Menu Handlers @IBAction func copy(_ sender: Any?) {