Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editor/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
isSelectionEnabled,
} from '../../store/selectors';
import { startMultiSelect, stopMultiSelect, multiSelect, selectBlock } from '../../store/actions';
import { isInputField } from '../../utils/dom';
import { documentHasSelection } from '../../utils/dom';

class BlockList extends Component {
constructor( props ) {
Expand Down Expand Up @@ -116,7 +116,7 @@ class BlockList extends Component {
}

// Let native copy behaviour take over in input fields.
if ( selectedBlock && isInputField( document.activeElement ) ) {
if ( selectedBlock && documentHasSelection() ) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions editor/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,20 @@ export function isInputField( { nodeName, contentEditable } ) {
contentEditable === 'true'
);
}

/**
* Check wether the current document has a selection.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "wether" -> "whether"

* This checks both for focus in an input field and general text selection.
*
* @returns {Boolean} True if there is selection, false if not.
*/
export function documentHasSelection() {
if ( isInputField( document.activeElement ) ) {
return true;
}

const selection = window.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

return range && ! range.collapsed;
}