iOS copy and cut keyboard shortcuts are not working
code-server1.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
- Open and edit a file.
- Try using „cmd+c“ or „cmd+x“.
- Change the shortcuts in the settings.
- Fail again.
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?
Unfortunately scrolling is not working.
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.
@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.
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.
@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(_:)andcut(_:)are methods from https://developer.apple.com/documentation/uikit/uiresponderstandardeditactions.WKWebViewimplements 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!
Last time I checked Copy and Paste worked on Theia. You guys could give that one a try.
@pr1metine tried it and it was meh. Not as refined as code-server.
Is there any chance of @ColdGrub1384 workaround being implemented in a coming V3?
@perelin That's not possible. Not the same workaround at least. He "fixed" it on app level. Not server level.
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".
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.
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.
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.
iOS Copy & Cut issue.
Maybe it is iPad issue.
https://github.com/microsoft/vscode/issues/101564
https://github.com/microsoft/vscode/pull/101702
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.
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.
@perelin Thanks for sharing! 20 upvotes now. 👍👍
Woo hoo
@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