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
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: check current editor has focus
  • Loading branch information
li-yechao committed Jun 4, 2025
commit 7fa08a92c9dec4219b7268d3d1bf1db3c28a936a
8 changes: 5 additions & 3 deletions patches/clipboard.diff
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,20 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
===================================================================
--- code-server.orig/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
+++ code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
@@ -15,19 +15,36 @@ import { IWorkbenchEnvironmentService }
@@ -15,19 +15,38 @@ import { IWorkbenchEnvironmentService }
import { ILogService } from '../../../../platform/log/common/log.js';
import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';
import { getActiveWindow } from '../../../../base/browser/dom.js';
+import { isSafari } from '../../../../base/browser/browser.js';
+import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
+import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';

export class BrowserClipboardService extends BaseBrowserClipboardService {

constructor(
@INotificationService private readonly notificationService: INotificationService,
+ @IContextKeyService private readonly contextKeyService: IContextKeyService,
+ @ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@IOpenerService private readonly openerService: IOpenerService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@ILogService logService: ILogService,
Expand All @@ -158,7 +160,7 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
+ if (isSafari) {
+ window.addEventListener('keydown', event => {
+ if (
+ (event.key.toLowerCase() === 'p' && this.contextKeyService.getContextKeyValue('vim.mode') === 'Normal') ||
+ (event.key.toLowerCase() === 'p' && this.contextKeyService.getContextKeyValue('vim.mode') === 'Normal' && this.codeEditorService.getActiveCodeEditor()?.hasTextFocus()) ||
+ (event.key === 'v' && (event.ctrlKey || event.metaKey) && this.contextKeyService.getContextKeyValue('vim.mode') === 'SearchInProgressMode')
+ ) {
+ this.lastClipboardTextContent = navigator.clipboard.readText()
Expand All @@ -174,7 +176,7 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
override async writeText(text: string, type?: string): Promise<void> {
if (!!this.environmentService.extensionTestsLocationURI && typeof type !== 'string') {
type = 'vscode-tests'; // force in-memory clipboard for tests to avoid permission issues
@@ -46,6 +63,15 @@ export class BrowserClipboardService ext
@@ -46,6 +65,15 @@ export class BrowserClipboardService ext
}

try {
Expand Down