Skip to content

Commit 4004b99

Browse files
committed
Support read clipboard in safari
1 parent 409c64e commit 4004b99

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

patches/clipboard.diff

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,37 @@ Index: code-server/lib/vscode/src/vs/server/node/server.cli.ts
133133
if (parsedArgs.status) {
134134
await sendToPipe({
135135
type: 'status'
136+
Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
137+
===================================================================
138+
--- code-server.orig/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
139+
+++ code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
140+
@@ -26,8 +26,17 @@ export class BrowserClipboardService ext
141+
@ILayoutService layoutService: ILayoutService
142+
) {
143+
super(layoutService, logService);
144+
+ window.addEventListener('keydown', event => {
145+
+ if (event.key.toLowerCase() === 'p' || (event.key === 'v' && (event.ctrlKey || event.metaKey))) {
146+
+ this.lastClipboardTextContent = navigator.clipboard.readText()
147+
+ this.lastCLipboardTime = Date.now();
148+
+ }
149+
+ })
150+
}
151+
152+
+ private lastClipboardTextContent?: Promise<string>
153+
+ private lastCLipboardTime?: number
154+
+
155+
override async writeText(text: string, type?: string): Promise<void> {
156+
if (!!this.environmentService.extensionTestsLocationURI && typeof type !== 'string') {
157+
type = 'vscode-tests'; // force in-memory clipboard for tests to avoid permission issues
158+
@@ -46,6 +55,11 @@ export class BrowserClipboardService ext
159+
}
160+
161+
try {
162+
+ if (this.lastClipboardTextContent && this.lastCLipboardTime && Date.now() - this.lastCLipboardTime < 1000) {
163+
+ const content = await this.lastClipboardTextContent;
164+
+ if (content) return content
165+
+ }
166+
+
167+
return await getActiveWindow().navigator.clipboard.readText();
168+
} catch (error) {
169+
return new Promise<string>(resolve => {

0 commit comments

Comments
 (0)