Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 22, 2022
1 parent 178660c commit c245115
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
17 changes: 11 additions & 6 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ export default function BlockTools( {
[]
);
const isMatch = useShortcutEventMatch();
const { getSelectedBlockClientIds, getBlockRootClientId } = useSelect(
blockEditorStore
);
const {
getSelectedBlockClientIds,
getBlockRootClientId,
getSelectionStart,
} = useSelect( blockEditorStore );
const {
duplicateBlocks,
removeBlocks,
Expand Down Expand Up @@ -131,22 +133,25 @@ export default function BlockTools( {
const blockA = getBlockNode( anchorNode );
const blockB = getBlockNode( focusNode );

event.preventDefault();

const selectionStart = getSelectionStart();

// To do: find other way to check if blocks are mergeable.
if (
isSimpleContentEditable( blockA ) &&
isSimpleContentEditable( blockB ) &&
blockA !== blockB
blockA !== blockB &&
selectionStart.attributeKey
) {
mergeBlocks(
first( clientIds ),
last( clientIds ),
clientIds.slice( 1, -1 )
);
event.preventDefault();
return;
}

event.preventDefault();
removeBlocks( clientIds );
} else if ( isMatch( 'core/block-editor/unselect', event ) ) {
const clientIds = getSelectedBlockClientIds();
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ export const mergeBlocks = (

// To do: merge logic with existing mergeBlocks logic.
if ( selectionStart.clientId !== selectionEnd.clientId ) {
if ( ! selectionStart.attributeKey || ! selectionEnd.attributeKey ) {
return;
}

let selectionA, selectionB;

if ( selectionStart.clientId === clientIdA ) {
Expand Down
10 changes: 8 additions & 2 deletions packages/rich-text/src/component/use-input-and-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ export function useInputAndSelection( props ) {
const selection = defaultView.getSelection();
const { anchorNode, focusNode } = selection;

if ( element.contains( anchorNode ) ) {
if (
element.contains( anchorNode ) &&
element !== anchorNode
) {
const { start, end: offset = start } = createRecord();
record.current.activeFormats = EMPTY_ACTIVE_FORMATS;
onSelectionChange( offset );
} else if ( element.contains( focusNode ) ) {
} else if (
element.contains( focusNode ) &&
element !== focusNode
) {
const { start, end: offset = start } = createRecord();
record.current.activeFormats = EMPTY_ACTIVE_FORMATS;
onSelectionChange( undefined, offset );
Expand Down

0 comments on commit c245115

Please sign in to comment.