code-server icon indicating copy to clipboard operation
code-server copied to clipboard

iOS copy and cut keyboard shortcuts are not working

Open schradeyannik opened this issue 7 years ago • 98 comments

  • code-server 1.1156-vsc1.33.1
  • OS Version: iPadOS 13.1 Beta 4 (on iPad Pro 2018 12.9)

Description

The keyboard shortcuts for copying and cutting text don‘t work. Changing the shortcuts in the code-server settings to something different of „cmd+c“ and „cmd+x“ does not help.

Steps to Reproduce

  1. Open and edit a file.
  2. Try using „cmd+c“ or „cmd+x“.
  3. Change the shortcuts in the settings.
  4. Fail again.

schradeyannik avatar Sep 20 '19 20:09 schradeyannik

For those using an iPad, you can temporarily use this app called VS App - code server, they pushed an update to the app that fixes copy/paste. You can use your custom code server in the app itself and not have to pay

Nice to hear, but what exactly is the fix? Can't we implement into code-server?

No idea, it's closed source i believe. Just found out that they pushed the update for this fix and i decided to try if it works with my custom code-server and it did.

Just tested it and it works! Thanks for sharing.

I just firgured out that @ColdGrub1384 is the developer. Maybe he can give us more insides?

rpweb avatar May 20 '20 09:05 rpweb

Unfortunately scrolling is not working.

rpweb avatar May 20 '20 09:05 rpweb

Yes thats a regular problem in both code-server and the app, for now i use a combination of touch scroll, shortcuts to jump between scroll pages, and the mini-map.

neoighodaro avatar May 20 '20 09:05 neoighodaro

@rpweb The WebView didn’t seem to receive Copy Paste shortcuts, so I added a listener in the app level that then sends Copy and Paste events. It’s just Swift code, no JavaScript.

That’s the code I have in the WebView:

class WebView: WKWebView {
    
    override func willMove(toWindow newWindow: UIWindow?) {
        super.willMove(toWindow: newWindow)
        
        let cut = UIBarButtonItem(image: UIImage(systemName: "scissors"), style: .plain, target: self, action: #selector(cut(_:)))
        
        let copyItem = UIBarButtonItem(image: UIImage(systemName: "doc.on.doc"), style: .plain, target: self, action: #selector(copy(_:)))
        
        let pasteItem = UIBarButtonItem(image: UIImage(systemName: "doc.on.clipboard"), style: .plain, target: self, action: #selector(paste(_:)))
                
        let done = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(endEditing(_:)))
        
        if UIDevice.current.userInterfaceIdiom == .pad {
            inputAssistantItem.trailingBarButtonGroups = []
            inputAssistantItem.leadingBarButtonGroups = [UIBarButtonItemGroup(barButtonItems: [cut, copyItem, pasteItem], representativeItem: nil)]
        } else {
            toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 500, height: 44))
            toolbar?.tintColor = .label
            toolbar?.items = [
                cut,
                copyItem,
                pasteItem,
                UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
                done
            ]
        }
    }
    
    @objc func _copy(_ sender: Any) {
        NSLog("Copy")
        copy(sender)
    }
    
    @objc func _cut(_ sender: Any) {
        NSLog("Cut")
        cut(sender)
    }
    
    @objc func _paste(_ sender: Any) {
        NSLog("Paste")
        paste(sender)
    }
    
    override var keyCommands: [UIKeyCommand]? {
        return [
            UIKeyCommand(input: "c", modifierFlags: .command, action: #selector(_copy(_:))),
            UIKeyCommand(input: "x", modifierFlags: .command, action: #selector(_cut(_:))),
            UIKeyCommand(input: "v", modifierFlags: .command, action: #selector(_paste(_:))),
        ]
    }
        
    private var toolbar: UIToolbar?
    
    override var inputAccessoryView: UIView? {
        if UIDevice.current.userInterfaceIdiom == .pad {
            return nil
        } else {
            return toolbar
        }
    }
}

I don’t know what’s exactly the problem but that worked. Seems like the keyboard shortcut isn’t detected but sending the event manual works.

Edit: copy(_:), paste(_:) and cut(_:) are methods from https://developer.apple.com/documentation/uikit/uiresponderstandardeditactions. WKWebView implements these methods.

Well, my guess is that iOS doesn’t detect text as selected, so it doesn’t call copy(_:) when cmd+c is pressed so calling it manually works because there is no check, we just send the function. So maybe the problem is that text is not detected as selected?

As you can see in the code, I didn’t pass the iOS methods directly to the key commands, but I passed a method that called the other method. That’s because passing the methods directly didn’t work, so that would prove that iOS checks if text is selected before calling copy(_:) when cmd+c is pressed.

ColdGrub1384 avatar May 20 '20 13:05 ColdGrub1384

The WebView didn’t seem to receive Copy Paste shortcuts, so I added a listener in the app level that then sends Copy and Paste events. It’s just Swift code, no JavaScript.

I called it! v3 does not implement the clipboard API in the editor from v2 because v3's terminal works just fine.

demyxco avatar May 20 '20 18:05 demyxco

@rpweb The WebView didn’t seem to receive Copy Paste shortcuts, so I added a listener in the app level that then sends Copy and Paste events. It’s just Swift code, no JavaScript.

That’s the code I have in the WebView:

class WebView: WKWebView {
    
    override func willMove(toWindow newWindow: UIWindow?) {
        super.willMove(toWindow: newWindow)
        
        let cut = UIBarButtonItem(image: UIImage(systemName: "scissors"), style: .plain, target: self, action: #selector(cut(_:)))
        
        let copyItem = UIBarButtonItem(image: UIImage(systemName: "doc.on.doc"), style: .plain, target: self, action: #selector(copy(_:)))
        
        let pasteItem = UIBarButtonItem(image: UIImage(systemName: "doc.on.clipboard"), style: .plain, target: self, action: #selector(paste(_:)))
                
        let done = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(endEditing(_:)))
        
        if UIDevice.current.userInterfaceIdiom == .pad {
            inputAssistantItem.trailingBarButtonGroups = []
            inputAssistantItem.leadingBarButtonGroups = [UIBarButtonItemGroup(barButtonItems: [cut, copyItem, pasteItem], representativeItem: nil)]
        } else {
            toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 500, height: 44))
            toolbar?.tintColor = .label
            toolbar?.items = [
                cut,
                copyItem,
                pasteItem,
                UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
                done
            ]
        }
    }
    
    @objc func _copy(_ sender: Any) {
        NSLog("Copy")
        copy(sender)
    }
    
    @objc func _cut(_ sender: Any) {
        NSLog("Cut")
        cut(sender)
    }
    
    @objc func _paste(_ sender: Any) {
        NSLog("Paste")
        paste(sender)
    }
    
    override var keyCommands: [UIKeyCommand]? {
        return [
            UIKeyCommand(input: "c", modifierFlags: .command, action: #selector(_copy(_:))),
            UIKeyCommand(input: "x", modifierFlags: .command, action: #selector(_cut(_:))),
            UIKeyCommand(input: "v", modifierFlags: .command, action: #selector(_paste(_:))),
        ]
    }
        
    private var toolbar: UIToolbar?
    
    override var inputAccessoryView: UIView? {
        if UIDevice.current.userInterfaceIdiom == .pad {
            return nil
        } else {
            return toolbar
        }
    }
}

I don’t know what’s exactly the problem but that worked. Seems like the keyboard shortcut isn’t detected but sending the event manual works.

Edit: copy(_:), paste(_:) and cut(_:) are methods from https://developer.apple.com/documentation/uikit/uiresponderstandardeditactions. WKWebView implements these methods.

Well, my guess is that iOS doesn’t detect text as selected, so it doesn’t call copy(_:) when cmd+c is pressed so calling it manually works because there is no check, we just send the function. So maybe the problem is that text is not detected as selected?

As you can see in the code, I didn’t pass the iOS methods directly to the key commands, but I passed a method that called the other method. That’s because passing the methods directly didn’t work, so that would prove that iOS checks if text is selected before calling copy(_:) when cmd+c is pressed.

Its a pitty that Apple can't provide a sustainable solution yet. Thank you for sharing your workaround!

rpweb avatar May 20 '20 19:05 rpweb

Last time I checked Copy and Paste worked on Theia. You guys could give that one a try.

pr1metine avatar May 21 '20 06:05 pr1metine

@pr1metine tried it and it was meh. Not as refined as code-server.

demyxco avatar May 21 '20 09:05 demyxco

Is there any chance of @ColdGrub1384 workaround being implemented in a coming V3?

perelin avatar May 21 '20 13:05 perelin

@perelin That's not possible. Not the same workaround at least. He "fixed" it on app level. Not server level.

neoighodaro avatar May 21 '20 13:05 neoighodaro

After a long trek in Azure-land -- I can confirm that this is also a problem in Microsoft Visual Studio Codespaces as well. When trying that version out on Chrome on my iPad (Safari doesn't work for some reason), copying doesn't work. You can paste text (cmd-V) that was already in the clipboard, but you can't paste new data. Similarly, cmd-Z doesn't work for undo either.

Interestingly, in code-server, you can copy from the terminal; however, in VS Codespaces, you can't copy from that terminal.

This makes me suspect that changes upstream are the primary cause for the lack of copy/paste/undo functionality in code-server as well. Given that this will be the basis for their Github codespaces product, I would wager that these problems will probably also get fixed upstream. Until then, VS App might be the best "workaround".

mbreese avatar May 21 '20 20:05 mbreese

Another workaround is installing the extension „Copy Copy Paste“ and assign Cmd+V to its paste action. It gives you an extra „hit return“ after paste, but otherwise works great at least for copy. Cut does not delete the selected text - you have to delete it on your own.

markuzzi avatar Jun 11 '20 08:06 markuzzi

This probably looks like a userAgent problem?

  • PC Chrome: Working
  • PC Chrome iOS Mobile Mode: Not Working
  • Safari: Working
  • Safari iPhone agent: Not Working
  • iPad Desktop Mode: Working
  • iPad Mobile Mode: Not Working

UserAgent (Test PC)

Test Code

<head>
...
<script>
Object.defineProperty(navigator, "userAgent", {
  get: () => "Mozilla/5.0 (Macintosh; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1",
});
// iOS "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
// Mac Safari "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15" = $1
</script>
...
</head>
...

Not Working

  • "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
  • "Mozilla/5.0 (What; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"

Working

  • "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15"
  • "Mozilla/5.0 (Macintosh; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"

Result

  • If userAgent does not have Macintosh, it does not work.
  • Probably because the userAgent checks the platform and the Macintosh uses the meta key. On the iPhone platform, it seems to cause the illusion of not using the meta key.

daybrush avatar Jun 23 '20 16:06 daybrush

Interesting On 23. Jun 2020, 18:00 +0200, Daybrush (Younkue Choi) [email protected], wrote:

This probably looks like a userAgent problem?

• PC Chrome: Working • PC Chrome iOS Mobile Mode: Not Working • Safari: Working • Safari iPhone agent: Not Working • iPad Desktop Mode: Working • iPad Mobile Mode: Not Working

UserAgent (Test PC) Test Code

... ... ... Not Working

• "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1" • "Mozilla/5.0 (What; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"

Working

• "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15" • "Mozilla/5.0 (Macintosh; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"

Result

• If userAgent does not have Macintosh, it does not work. • Probably because the userAgent checks the platform and the Macintosh uses the meta key. On the iPhone platform, it seems to cause the illusion of not using the meta key.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

neoighodaro avatar Jun 24 '20 05:06 neoighodaro

iOS Copy & Cut issue.

Maybe it is iPad issue.

https://github.com/microsoft/vscode/issues/101564

https://github.com/microsoft/vscode/pull/101702

daybrush avatar Jul 02 '20 05:07 daybrush

I totally missed it, but the issue created by @daybrush on the vscode repository needs upvotes to get considered: microsoft/vscode#101564

vscode-triage-bot commented 24 days ago This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it.

8 Upvotes so far. If everybody from this thread upvotes, we are good.

perelin avatar Jul 26 '20 04:07 perelin

I totally missed it, but the issue created by @daybrush on the vscode repository needs upvotes to get considered: microsoft/vscode#101564

vscode-triage-bot commented 24 days ago This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it.

8 Upvotes so far. If everybody from this thread upvotes, we are good.

9 now.

demyxco avatar Jul 26 '20 04:07 demyxco

@perelin Thanks for sharing! 20 upvotes now. 👍👍

wei avatar Jul 26 '20 11:07 wei

Woo hoo

neoighodaro avatar Jul 26 '20 15:07 neoighodaro

@perelin @wei @demyxco @neoighodaro

I hope this issue will be resolved quickly. I uploaded the PR, but the vscode cannot be checked.

https://github.com/microsoft/vscode/pull/101702

daybrush avatar Jul 26 '20 18:07 daybrush