8000 only this feature in safari · coder/code-server@5300db2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5300db2

Browse files
committed
only this feature in safari
1 parent a5d1be6 commit 5300db2

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

patches/clipboard.diff

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,26 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
137137
===================================================================
138138
--- code-server.orig/lib/vscode/src/vs/workbench/services/clipboard/browser/clipboardService.ts
139139
+++ 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
141149
@ILayoutService layoutService: ILayoutService
142150
) {
143151
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+
+ }
150160
}
151161

152162
+ private lastClipboardTextContent?: Promise<string>
@@ -155,13 +165,17 @@ Index: code-server/lib/vscode/src/vs/workbench/services/clipboard/browser/clipbo
155165
override async writeText(text: string, type?: string): Promise<void> {
156166
if (!!this.environmentService.extensionTestsLocationURI && typeof type !== 'string') {
157167
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
159169
}
160170

161171
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+
+ }
165179
+ }
166180
+
167181
return await getActiveWindow().navigator.clipboard.readText();

0 commit comments

Comments
 (0)
0