Skip to content

Commit 22939f9

Browse files
authored
fix: Fix pasting tailwind etc (#5519)
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 14f5525 commit 22939f9

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

apps/builder/app/builder/shared/commands.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { openDeleteUnusedCssVariablesDialog } from "~/builder/shared/css-variabl
6060
import { openKeyboardShortcutsDialog } from "~/builder/features/keyboard-shortcuts-dialog";
6161
import {
6262
copyInstance,
63-
pasteInstance,
63+
emitPaste,
6464
cutInstance,
6565
} from "~/shared/copy-paste/init-copy-paste";
6666
import { toggleInstanceShow } from "~/shared/instance-utils";
@@ -450,24 +450,18 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
450450
name: "copy",
451451
description: "Copy selected instance",
452452
category: "Navigator",
453-
defaultHotkeys: ["meta+c", "ctrl+c"],
454-
disableOnInputLikeControls: true,
455453
handler: copyInstance,
456454
},
457455
{
458456
name: "paste",
459457
description: "Paste copied instance",
460458
category: "Navigator",
461-
defaultHotkeys: ["meta+v", "ctrl+v"],
462-
disableOnInputLikeControls: true,
463-
handler: pasteInstance,
459+
handler: emitPaste,
464460
},
465461
{
466462
name: "cut",
467463
description: "Cut selected instance",
468464
category: "Navigator",
469-
defaultHotkeys: ["meta+x", "ctrl+x"],
470-
disableOnInputLikeControls: true,
471465
handler: cutInstance,
472466
},
473467
{

apps/builder/app/shared/copy-paste/init-copy-paste.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,20 @@ export const copyInstance = () => {
172172
}
173173
};
174174

175-
export const pasteInstance = async () => {
175+
export const emitPaste = async () => {
176176
const text = await navigator.clipboard.readText();
177-
instanceText.onPaste?.(text);
177+
178+
// Create and dispatch a paste event to go through the normal handlePaste flow
179+
const dataTransfer = new DataTransfer();
180+
dataTransfer.setData("text/plain", text);
181+
182+
const pasteEvent = new ClipboardEvent("paste", {
183+
clipboardData: dataTransfer,
184+
bubbles: true,
185+
cancelable: true,
186+
});
187+
188+
document.dispatchEvent(pasteEvent);
178189
};
179190

180191
export const cutInstance = () => {

0 commit comments

Comments
 (0)