Description
Current workarounds:
On Firefox you can use middle-mouse click or shift+insert (possibly depends on your OS). Pasting with the right-click menu will not work on Firefox but you can press shift+right click to get the native context menu and use that to paste. ctrl+v
will work in the editor but not the terminal.
On Chrome ctrl+shift+v
should work in the terminal and ctrl+v
should work in the editor. If you use Chrome over a secure domain and accept the clipboard prompt then the right click menu to paste will work for the terminal but not the editor.
Summary:
Currently only native paste or the clipboard API will work so there are certain cases where pasting will not work with the keybinding you'd expect (ctrl+shift+v
in the terminal) or with the right-click menu (see my comments below for details).
Original post:
Currently if you try to copy on an insecure domain you get "cannot read property writeText
of undefined` because it's trying to access the clipboard which is undefined in insecure contexts.
We could fall back to copying using document.execCommand("copy")
which I think is what the editor does. That seems to work fine.
For paste I believe the editor listens to the native paste
command. That's not an option for the terminal because it requires we use the native keybinding (ctrl+v
) and that has a different function in the terminal.
I've experimented with document.execCommand("paste")
in the past but it didn't work so I assume this is why VS Code didn't use it here although perhaps more research is warranted here. That means our only option is the browser clipboard API which is only available in secure contexts.
Having only copy but not paste available on the terminal doesn't seem like a good solution so I think our best bet is to detect when the context is insecure and display a message describing the need to use https.
Service workers don't work in an insecure context either so maybe it would be a good idea to display a message when the browser loads as well just so people are aware they're accessing code-server in an insecure way and that things might be broken (as well as just generally dangerous).
While we're at it we could also implement the editor paste command using the clipboard API which would resolve #1105.