Skip to content

Commit

Permalink
Writing flow: fix paste for input fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 6, 2024
1 parent d185a1b commit 5bf3327
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ export default function useClipboardHandler() {
return;
}

// Let native copy/paste behaviour take over in input fields.
// But always handle multiple selected blocks.
if ( ! hasMultiSelection() ) {
const { target } = event;
const { ownerDocument } = target;
// If copying, only consider actual text selection as selection.
// Otherwise, any focus on an input field is considered.
const hasSelection =
event.type === 'copy' || event.type === 'cut'
? documentHasUncollapsedSelection( ownerDocument )
: documentHasSelection( ownerDocument );

// Let native copy behaviour take over in input fields.
if ( hasSelection ) {
return;
}
}

const { activeElement } = event.target.ownerDocument;

if ( ! node.contains( activeElement ) ) {
Expand All @@ -72,22 +90,6 @@ export default function useClipboardHandler() {
const expandSelectionIsNeeded =
! shouldHandleWholeBlocks && ! isSelectionMergeable;
if ( event.type === 'copy' || event.type === 'cut' ) {
if ( ! hasMultiSelection() ) {
const { target } = event;
const { ownerDocument } = target;
// If copying, only consider actual text selection as selection.
// Otherwise, any focus on an input field is considered.
const hasSelection =
event.type === 'copy' || event.type === 'cut'
? documentHasUncollapsedSelection( ownerDocument )
: documentHasSelection( ownerDocument );

// Let native copy behaviour take over in input fields.
if ( hasSelection ) {
return;
}
}

event.preventDefault();

if ( selectedBlockClientIds.length === 1 ) {
Expand Down

0 comments on commit 5bf3327

Please sign in to comment.