From e9a960dca71b8fdb41254904bb4029246b207378 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 26 Dec 2025 23:21:42 +0000 Subject: [PATCH] fix(vscode): improve paste support for vscode extension --- frontend/src/lib/components/Dev.svelte | 37 ++++++++++++++- frontend/src/lib/components/DiffEditor.svelte | 33 +++++++++++++- frontend/src/lib/components/Editor.svelte | 32 +++++++++++++ .../lib/components/GraphqlSchemaViewer.svelte | 10 ++++- frontend/src/lib/components/JsonInputs.svelte | 25 +++++++---- .../src/lib/components/SimpleEditor.svelte | 45 +++++++++++++++++++ .../src/lib/components/TemplateEditor.svelte | 30 +++++++++++++ 7 files changed, 199 insertions(+), 13 deletions(-) diff --git a/frontend/src/lib/components/Dev.svelte b/frontend/src/lib/components/Dev.svelte index 9c5de746c9..b85c3b7c9b 100644 --- a/frontend/src/lib/components/Dev.svelte +++ b/frontend/src/lib/components/Dev.svelte @@ -1,5 +1,6 @@ - + -
+
{ diff --git a/frontend/src/lib/components/SimpleEditor.svelte b/frontend/src/lib/components/SimpleEditor.svelte index 083bb30577..884fab737c 100644 --- a/frontend/src/lib/components/SimpleEditor.svelte +++ b/frontend/src/lib/components/SimpleEditor.svelte @@ -360,6 +360,21 @@ } keepModelAroundToAvoidDisposalOfWorkers() + // In VSCode webview (iframe), clipboard operations need special handling + // because the webview has restricted clipboard API access + if (window.parent !== window) { + editor.addCommand(KeyMod.CtrlCmd | KeyCode.KeyC, function () { + document.execCommand('copy') + }) + editor.addCommand(KeyMod.CtrlCmd | KeyCode.KeyX, function () { + document.execCommand('cut') + }) + editor.addCommand(KeyMod.CtrlCmd | KeyCode.KeyV, async function () { + inputEl?.focus() + document.execCommand('paste') + }) + } + let timeoutModel: number | undefined = undefined editor.onDidChangeModelContent((event) => { timeoutModel && clearTimeout(timeoutModel) @@ -583,8 +598,38 @@ } updatePlaceholderVisibility(code ?? '') + + let inputEl = $state(null) + let pasteValue = $state('') + $effect(() => { + if (inputEl && pasteValue) { + untrack(() => { + editor?.executeEdits('paste', [ + { + range: editor?.getSelection() ?? { + startLineNumber: 1, + startColumn: 1, + endLineNumber: 1, + endColumn: 1 + }, + text: pasteValue, + forceMoveMarkers: true + } + ]) + pasteValue = '' + }) + } + }) +{#if parent.window !== window} + +{/if} {#if !editor || suggestion} { dispatch('focus')