@@ -137,16 +137,26 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
137
137
===================================================================
138
138
--- code-server.orig/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
139
139
+++ code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
140
- @@ -26,8 +26,17 @@ export class BrowserClipboardService ext
140
+ @@ -15,6 +15,7 @@ import { IWorkbenchEnvironmentService }
141
+ import { ILogService } from '../../../../platform/log/common/log.js';
142
+ import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';
143
+ import { getActiveWindow } from '../../../../base/browser/dom.js';
144
+ + import { isSafari } from '../../../../base/browser/browser.js';
145
+
146
+ export class BrowserClipboardService extends BaseBrowserClipboardService {
147
+
148
+ @@ -26,8 +27,19 @@ export class BrowserClipboardService ext
141
149
@ILayoutService layoutService: ILayoutService
142
150
) {
143
151
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
- + })
152
+ + if (isSafari) {
153
+ + window.addEventListener('keydown', event => {
154
+ + if (event.key.toLowerCase() === 'p' || (event.key === 'v' && (event.ctrlKey || event.metaKey))) {
155
+ + this.lastClipboardTextContent = navigator.clipboard.readText()
156
+ + this.lastCLipboardTime = Date.now();
157
+ + }
158
+ + })
159
+ + }
150
160
}
151
161
152
162
+ private lastClipboardTextContent?: Promise<string>
@@ -155,13 +165,17 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
155
165
override async writeText(text: string, type?: string): Promise<void> {
156
166
if (!!this.environmentService.extensionTestsLocationURI && typeof type !== 'string') {
157
167
type = 'vscode-tests'; // force in-memory clipboard for tests to avoid permission issues
158
- @@ -46,6 +55,11 @@ export class BrowserClipboardService ext
168
+ @@ -46,6 +58,15 @@ export class BrowserClipboardService ext
159
169
}
160
170
161
171
try {
162
- + if (this.lastClipboardTextContent && this.lastCLipboardTime && Date.now() - this.lastCLipboardTime < 1000) {
163
- + const content = await this.lastClipboardTextContent;
164
- + if (content) return content
172
+ + if (isSafari && this.lastClipboardTextContent && this.lastCLipboardTime && Date.now() - this.lastCLipboardTime < 1000) {
173
+ + try {
174
+ + const content = await this.lastClipboardTextContent;
175
+ + if (content) return content
176
+ + } catch {
177
+ + // ignore error, we will try to read from the clipboard
178
+ + }
165
179
+ }
166
180
+
167
181
return await getActiveWindow().navigator.clipboard.readText();
0 commit comments