Skip to content

Commit 132091c

Browse files
committed
Add alternate copy and cut implementation to vscode.patch
Allows clipboard to function as expected on iPadOS beta. Resolves coder#569
1 parent f25a614 commit 132091c

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

scripts/vscode.patch

+43-13
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,55 @@ index 990be3a..18ae0d5 100644
267267
-const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste')));
268268
+// const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste')));
269269
+const supportsPaste = true;
270-
@@ -71 +73 @@ class ExecCommandCutAction extends ExecCommandAction {
271-
- kbOpts = null;
272-
+ // kbOpts = null;
273-
@@ -119 +121 @@ class ExecCommandCopyAction extends ExecCommandAction {
274-
- kbOpts = null;
275-
+ // kbOpts = null;
276-
@@ -174 +176 @@ class ExecCommandPasteAction extends ExecCommandAction {
277-
- kbOpts = null;
278-
+ // kbOpts = null;
279-
@@ -176,0 +179 @@ class ExecCommandPasteAction extends ExecCommandAction {
270+
@@ -103 +105,18 @@ class ExecCommandCutAction extends ExecCommandAction {
271+
- super.run(accessor, editor);
272+
+ let model = editor.getModel();
273+
+ let originalSelections = editor.getSelections().sort((a, b) => {
274+
+ if (a.startLineNumber < b.startLineNumber) return -1;
275+
+ if (a.startLineNumber > b.startLineNumber) return 1;
276+
+ if (a.startColumn < b.startColumn) return -1;
277+
+ return 1;
278+
+ });
279+
+ let selectionContent = originalSelections.map(selection => model.getValueInRange(selection)).join('\n');
280+
+ let textArea = document.createElement('textarea');
281+
+ textArea.value = selectionContent;
282+
+ textArea.style.position = 'absolute';
283+
+ textArea.style.left = '-9999px';
284+
+ document.body.appendChild(textArea);
285+
+ textArea.select();
286+
+ document.execCommand('copy');
287+
+ document.body.removeChild(textArea);
288+
+ editor.trigger('', (require('vs/editor/common/editorCommon') as typeof import('vs/editor/common/editorCommon')).Handler.Cut, null);
289+
+ editor.focus();
290+
@@ -158 +178,17 @@ class ExecCommandCopyAction extends ExecCommandAction {
291+
- super.run(accessor, editor);
292+
+ let model = editor.getModel();
293+
+ let originalSelections = editor.getSelections().sort((a, b) => {
294+
+ if (a.startLineNumber < b.startLineNumber) return -1;
295+
+ if (a.startLineNumber > b.startLineNumber) return 1;
296+
+ if (a.startColumn < b.startColumn) return -1;
297+
+ return 1;
298+
+ });
299+
+ let selectionContent = originalSelections.map(selection => model.getValueInRange(selection)).join('\n');
300+
+ let textArea = document.createElement('textarea');
301+
+ textArea.value = selectionContent;
302+
+ textArea.style.position = 'absolute';
303+
+ textArea.style.left = '-9999px';
304+
+ document.body.appendChild(textArea);
305+
+ textArea.select();
306+
+ document.execCommand('copy');
307+
+ document.body.removeChild(textArea);
308+
+ editor.focus();
309+
@@ -176,0 +212 @@ class ExecCommandPasteAction extends ExecCommandAction {
280310
+ const { workbench } = require('vs/../../../../packages/vscode/src/workbench') as typeof import ('vs/../../../../packages/vscode/src/workbench');
281-
@@ -181 +184 @@ class ExecCommandPasteAction extends ExecCommandAction {
311+
@@ -181 +219 @@ class ExecCommandPasteAction extends ExecCommandAction {
282312
- precondition: EditorContextKeys.writable,
283313
+ precondition: (require('vs/platform/contextkey/common/contextkey') as typeof import('vs/platform/contextkey/common/contextkey')).ContextKeyExpr.and(EditorContextKeys.writable, workbench.clipboardContextKey),
284-
@@ -191 +194,2 @@ class ExecCommandPasteAction extends ExecCommandAction {
314+
@@ -191 +227,2 @@ class ExecCommandPasteAction extends ExecCommandAction {
285315
- order: 3
286316
+ order: 3,
287317
+ when: workbench.clipboardContextKey,
288-
@@ -194,0 +199,26 @@ class ExecCommandPasteAction extends ExecCommandAction {
318+
@@ -194,0 +232,26 @@ class ExecCommandPasteAction extends ExecCommandAction {
289319
+
290320
+ public async run(accessor, editor: ICodeEditor): Promise<void> {
291321
+ if (editor instanceof (require('vs/editor/browser/widget/codeEditorWidget') as typeof import('vs/editor/browser/widget/codeEditorWidget')).CodeEditorWidget) {

0 commit comments

Comments
 (0)