Skip to content

Commit

Permalink
copy instance if no text selected
Browse files Browse the repository at this point in the history
  • Loading branch information
kof committed Feb 11, 2025
1 parent 9e710f4 commit 99a2995
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions apps/builder/app/shared/copy-paste/init-copy-paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,10 @@ const validateClipboardEvent = (event: ClipboardEvent) => {
// Allows native selection of text in the Builder panels, such as CSS Preview.
if (event.type === "copy") {
const isInBuilderContext = window.self === window.top;
const selection = window.getSelection();

if (isInBuilderContext) {
// Note on event.target:
//
// The spec (https://w3c.github.io/clipboard-apis/#to-fire-a-clipboard-event)
// says that if the context is not editable, the target should be the focused node.
//
// But in practice it seems that the target is based
// on where the cursor is, rather than which element has focus.
// For example, if a <button> has focus, the target is the <body> element.
// If some text is selected, the target is a wrapping element of the text.
// (at least in Chrome).

// We are using the behavior described above: if some text is selected, the target is usually (at least in the cases we need) not the body.
if (event.target !== window.document.body) {
return false;
}
if (isInBuilderContext && selection && selection.isCollapsed === false) {
return false;
}
}

Expand Down

0 comments on commit 99a2995

Please sign in to comment.