diff --git a/Boop/Boop/Controllers/PopoverViewController.swift b/Boop/Boop/Controllers/PopoverViewController.swift index da7748a0..6e1f67e2 100644 --- a/Boop/Boop/Controllers/PopoverViewController.swift +++ b/Boop/Boop/Controllers/PopoverViewController.swift @@ -28,6 +28,14 @@ class PopoverViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() + + // Double-click script selection + tableView.doubleAction = #selector(runSelectedScript) + + // Dismiss popover on background view click + overlayView.onMouseDown = { [weak self] in + self?.hide() + } setupKeyHandlers() } @@ -55,18 +63,12 @@ class PopoverViewController: NSViewController { } if theEvent.keyCode == 36 && self.enabled { // ENTER - - guard let script = self.tableViewController.selectedScript else { - return theEvent // Return event to beep + + guard self.tableViewController.selectedScript != nil else { + return theEvent } - - - // Let's dismiss the popover - self.hide() - - // Run the script afterwards in case we need to show a status - self.scriptManager.runScript(script, into: self.editorView) - + + self.runSelectedScript() didSomething = true } @@ -142,6 +144,18 @@ class PopoverViewController: NSViewController { func runScriptAgain() { self.scriptManager.runScriptAgain(editor: self.editorView) } + + @objc private func runSelectedScript() { + guard let script = tableViewController.selectedScript else { + return + } + + // Let's dismiss the popover + hide() + + // Run the script afterwards in case we need to show a status + scriptManager.runScript(script, into: editorView) + } } diff --git a/Boop/Boop/Views/OverlayView.swift b/Boop/Boop/Views/OverlayView.swift index 5beb372b..aa99543a 100644 --- a/Boop/Boop/Views/OverlayView.swift +++ b/Boop/Boop/Views/OverlayView.swift @@ -10,6 +10,8 @@ import Cocoa class OverlayView: NSView { + var onMouseDown: (() -> Void)? + required init?(coder decoder: NSCoder) { super.init(coder: decoder) self.wantsLayer = true @@ -32,7 +34,7 @@ class OverlayView: NSView { } override func mouseDown(with event: NSEvent) { - return + onMouseDown?() } }