code-server: iOS copy and cut keyboard shortcuts are not working

  • 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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 16
  • Comments: 98 (16 by maintainers)

Most upvoted comments

Merged the latest VS Code, will be in 3.6.0 very soon. Keep an eye on the milestone to see progress.

This just got merged upstream! 😉

FYI a simple workaround I’ve used is to highlight the text, cmd+f, and then you can immediately cmd+c out of the search bar. Paste works as expected. This doesn’t solve cut, but it’s pretty usable

@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.

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.

Merged the latest VS Code, will be in 3.6.0 very soon. Keep an eye on the milestone to see progress.

It works!

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.

Ah. I assume we could patch that quite easily.

please use desktop mode in safari. trun on : Setting—Safari—Request dessktop website

Good news August 2020 milestone is in endgame. They are targeting next Wednesday/Thursday for release. Let’s hope code-server team can bump up vscode version quicker this time 😉

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

@rpweb Thats awesome, will definitely help us debug easier.

V3: I could reproduce the issue on MacOS when I emulate iPad in Chrome code-server via inspector! Bildschirmfoto 2020-04-28 um 21 27 07

Good news August 2020 milestone is in endgame. They are targeting next Wednesday/Thursday for release. Let’s hope code-server team can bump up vscode version quicker this time 😉

My hopes are so high for today, Thursday.

@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

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”.

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

I’m pretty sure this is because WebKit doesn’t let us override copy/paste on mobile unfortunately.

On iOS the copy button is just greyed out. It’s like text selection doesn’t recognise that text has been highlighted in the editor view. Paste does work already if you’ve got something in the clipboard.

Seeing the same behavior. If it is a quick patch would love to see this fixed!

@kschembri Waiting for https://github.com/microsoft/vscode/wiki/Iteration-Plans Says August 2020 milestone to be released in early September. Then wait for code-server to pull it in. Currently there is an open PR in this repo to bump up vscode to its July 2020 milestone release. We’ll just have to wait maybe another 2 months 🤦 .

Awesome, then we just need to update our vs code version!

@ethanx94

Nice!! It will release august 2020

Hi @mbreese thanks for your feedback, I really appreciate it. I have a question: why is it possible to copy for instance the path of a file? image This one works for me on my iPad, updated with the latest iPad OS.

Is this in contradiction with your conclusions? Might be this is not, since this button is acting on an element that is outside of the editor view or maybe because this is not using a keyboard shortcut…

Yes, that works. But I think the difference is where the source of the clipboard text is. Even above, I mentioned that I could still paste w/ cmd-V, but only something that was clipped from a different app (like notes, email, or the safari url, etc).

So, what we’ve shown is that you can a) programmatically add data to the clipboard and b) programmatically paste data from the clipboard

What you can’t do is copy user-data to the clipboard. So, my guess is that it’s somewhere in the selection API. If you run (from the console):

window.getSelection().toString()

On Safari on my Mac, I get the correct selected text. On my iPad, I get an empty string (""). I think this is where the root issue lies.

You’re right that this all seems strange and contradictory. It also seems like it doesn’t match the Webkit announcement at all. The rest of it may end up a red herring. I believe that any copy/paste code needs to run in the context of a user event (keydown, pointerdown, etc). The tests I’ve been doing haven’t done that, so maybe that’s another issue with the testing?

And strangely, undo/redo also works. I expect that’s a similar mechanism as copy/paste. As does dragging and dropping… (select code, drag it around to move it someplace else).

Finally to add to the confusion… from @code-asher above,

For the terminal it uses the clipboard API if it can but for the editor I don’t think it does. I think it just uses native paste there.

You can copy from the terminal and paste into the editor. So, maybe there is hope afterall!

I’ve been fighting with this for the better part of a week, and I think I understand what is happening. Strangely, what I’ve seen is that I can paste anything, but I can’t copy anything new into the clipboard. If the clipboard already has the information I want, then it can be read with cmd-V, as expected.

I loaded my iPad up in the Safari remote debugger (by plugging the iPad into my computer via usb-c), and was looking for some error messages. I didn’t see anything when I tried to use cmd-C. So, I tried programmatically copy/pasting.

What I saw was this:

Screen Shot 2020-05-05 at 1 27 58 PM

This led me to start looking for granting permissions to the clipboard in Safari. And unfortunately, I don’t think it will be possible. From my reading, I think that the only way for web applications to interact with the clipboard is using the system copy/paste UI. This is a recent update to the iPadOS/Safari code. And this obviously won’t work with an editor like code-server/VSCode that is expecting to be able to use keyboard shortcuts.

Here’s the update from Webkit that mentions this behavior: https://webkit.org/blog/10247/new-webkit-features-in-safari-13-1/

The implementation is available through the navigator.clipboard API which must be called within user gesture event handlers like pointerdown or pointerup, and only works for content served in a secure context (e.g. https://). Instead of a permissions-based model for reading from the clipboard, a native UI is displayed when the page calls into the clipboard API; the clipboard can only be accessed if the user then explicitly interacts with the platform UI.

So, the issue maybe a combination of code-server and the version of iPadOS in use. I’m not sure if there is a work around…

To confirm, cmd+c, cmd+x, and cmd+v work when editing a file in v2 but not in v3?

Correct. Though in v3, paste gets disabled when switching tabs. It’s probably due to it losing focus from the attempting to reconnect dialog? You have to click the terminal first then the editor to paste again.

@schradeyannik AFAIK we do not support Safari in mobile mode, try using the Desktop mode. We have no plans to support mobile UAs due to Monaco’s limitation.

@keiqsa are you using a self hosted instance of code-server with the Servediter app or their hosted service? I tried to get the app to connect to my self hosted server, but it didn’t work. Their app seems really buggy in general.

It’s been a while but I wanted you to know that I am using self-hosted server and it works well for me. I’ve just tried it /w code-server 3.3.1.

I just installed v3.5.0. I can confirm that pasting works. However, I still cannot copy. Anyone else seeing this or is that an issue that only I am facing? 🙂

  • 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

I was able to get copy/paste working using the iCabMobile browser, which lets you change the user agent. Definitely a hack, but its better than nothing.

Great, feedback. I just paid my AU$4.50 for iCabMobile and have dedicated it to this single purpose. Love how it can be customised. Full screen VSCode on the ipad pro works incredibly (while the macbook is in for service). Looking forward though to copy and paste running in Safari though

  • 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

I was able to get copy/paste working using the iCabMobile browser, which lets you change the user agent. Definitely a hack, but its better than nothing.

vscode-triage-bot commented 10 hours ago 🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog.

microsoft/vscode/issues/101564

Looking good!

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

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

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.

Ah, we removed the v2 tag but the individual v2 version tags are still there. Definitely sounds like it’s worth checking out.

That’s a brilliant temporary “fix”. Thank you.

Cmd + Shift + F allows you to copy entire blocks too.

Same behaviour here. iPad Air 3, iOS 13.4

I just tried out the last V2 and it works there.

Using a V2 is the only workaround currently? (no copy/paste makes development work defacto impossible 😃

Any update on this bug? I’m having the same issue. iOS 13.3 iPad Air version 3.

Edit: So this is only in V3. Using the last build of V2 I’m having no issues with cut/copy/paste

@mattapperson This does not work either.

@sr229 @phoenixsfly The desktop mode is activated. The mentioned keyboard shortcuts do not work in desktop mode.