Skip to content

Copy/Cut/Paste does not work on Mac #18

@stefanwagnerdev

Description

@stefanwagnerdev

I use this along with https://github.com/badlogic/pi-diff-review
I noticed that copy paste does not work on Mac in the comment windows.

My current hack is to trigger the copy paste functions if the key is pressed.
This works but only for mac. I havent tested if the other platforms have the same problem.

class GlimpsePanel: NSWindow {
    override var canBecomeKey: Bool { true }
    override var canBecomeMain: Bool { true }

    override func performKeyEquivalent(with event: NSEvent) -> Bool {
        if super.performKeyEquivalent(with: event) {
            return true
        }
        if NSApp.mainMenu?.performKeyEquivalent(with: event) == true {
            return true
        }

        // Accessory/frameless panel mode can bypass normal menu key-equivalent routing.
        // Fallback to responder-chain edit actions for standard clipboard shortcuts.
        let modifiers = event.modifierFlags.intersection(.deviceIndependentFlagsMask)
        guard modifiers == .command || modifiers == [.command, .shift] else {
            return false
        }

        guard let chars = event.charactersIgnoringModifiers?.lowercased() else {
            return false
        }

        let action: Selector?
        switch chars {
        case "c": action = #selector(NSText.copy(_:))
        case "x": action = #selector(NSText.cut(_:))
        case "v": action = #selector(NSText.paste(_:))
        case "a": action = #selector(NSText.selectAll(_:))
        default: action = nil
        }

        guard let action else {
            return false
        }

        return NSApp.sendAction(action, to: nil, from: self)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions