diff --git a/patches/clipboard.diff b/patches/clipboard.diff index ffcafe5dddb0..ee84b5c52481 100644 --- a/patches/clipboard.diff +++ b/patches/clipboard.diff @@ -133,3 +133,62 @@ Index: code-server/lib/vscode/src/vs/server/node/server.cli.ts if (parsedArgs.status) { await sendToPipe({ type: 'status' +Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts +=================================================================== +--- 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,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, + @ILayoutService layoutService: ILayoutService + ) { + super(layoutService, logService); ++ if (isSafari) { ++ window.addEventListener('keydown', event => { ++ if ( ++ (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() ++ this.lastCLipboardTime = Date.now(); ++ } ++ }) ++ } + } + ++ private lastClipboardTextContent?: Promise ++ private lastCLipboardTime?: number ++ + override async writeText(text: string, type?: string): Promise { + if (!!this.environmentService.extensionTestsLocationURI && typeof type !== 'string') { + type = 'vscode-tests'; // force in-memory clipboard for tests to avoid permission issues +@@ -46,6 +65,15 @@ export class BrowserClipboardService ext + } + + try { ++ if (isSafari && this.lastClipboardTextContent && this.lastCLipboardTime && Date.now() - this.lastCLipboardTime < 1000) { ++ try { ++ const content = await this.lastClipboardTextContent; ++ if (content) return content ++ } catch { ++ // ignore error, we will try to read from the clipboard ++ } ++ } ++ + return await getActiveWindow().navigator.clipboard.readText(); + } catch (error) { + return new Promise(resolve => {