Skip to content

Fix clipboard access issue for VIM extension in safari #7366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

li-yechao
Copy link

I typically use code-server in Safari with the VIM extension, but I've encountered issues with clipboard functionality due to the underlying VSCode architecture. After some exploration, I found a way to improve the clipboard experience in Safari: when certain events that can read the clipboard (such as pressing 'p' or 'ctrl+v') are triggered, the clipboard content is read into memory, and subsequent read requests within a short time window will return the cached content instead of reading from the clipboard

@li-yechao li-yechao requested a review from a team as a code owner June 3, 2025 15:04
@li-yechao li-yechao changed the title Support read clipboard in safari Fix Clipboard Access Issue for VIM Extension in Safari Jun 3, 2025
@li-yechao li-yechao changed the title Fix Clipboard Access Issue for VIM Extension in Safari Fix clipboard access issue for VIM extension in safari Jun 3, 2025
@li-yechao
Copy link
Author

Although this patch might seem a bit like a hack, it works surprisingly well in Safari.

@code-asher
Copy link
Member

code-asher commented Jun 3, 2025

Thank you for the patch! Could this fix be sent upstream to https://github.com/microsoft/vscode? At a glance it seems like something that should be fixed upstream to me.

The VS Code folks can probably give a better review than I can, but my gut says that specifically reacting to Vim keybindings in the core might not be the right implementation.

@li-yechao
Copy link
Author

@code-asher As you mentioned, I don’t think VSCode would accept this patch. Given that WebKit (the core of Safari) has no plans to open the clipboard API, and considering the limitations of both VSCode's architecture and WebKit, supporting this in a VSCode extension isn't feasible. For now, the only viable solution is to modify the VSCode core via a patch.

@li-yechao
Copy link
Author

Even if this PR doesn’t get merged, that’s perfectly fine—I totally understand. While this patch works, it is indeed quite a hack. My intention is simply to provide this solution for anyone who might find it useful.

@li-yechao li-yechao force-pushed the fix/safari-clipboard branch from 57847a8 to 87877e7 Compare June 4, 2025 00:34
@li-yechao li-yechao force-pushed the fix/safari-clipboard branch from e962d31 to 7fa08a9 Compare June 4, 2025 02:28
@code-asher
Copy link
Member

That makes sense! Yeah I think it is not something we should merge so I will close but we can use this as an example if anyone else has issues.

Speaking of, what is the issue exactly? Is it that sometimes pasting does not work, specifically when pasting in rapid succession?

@code-asher code-asher closed this Jun 4, 2025
@li-yechao
Copy link
Author

Speaking of, what is the issue exactly? Is it that sometimes pasting does not work, specifically when pasting in rapid succession?

When you install VIM extension and enable "vim.useSystemClipboard": true, p (paste function) in vim mode will be unavailable (in safari), because vscode's clipboard API calls navigator.clipboard.readText(), which must be called in events directly triggered by the user in webkit-based browsers, and vscode calls this API in the request of VIM Extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants