Skip to content

Commit

Permalink
Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Jun 5, 2020
1 parent 5a3ba5c commit 9e18fc7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/ckeditor5-ui/src/toolbar/balloon/balloontoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,24 @@ function getBalloonPositions( isBackward ) {
];
}

// Returns "true" when the selection has multiple ranges and each range contains an object
// and nothing else.
//
// @private
// @param {module:engine/model/selection~Selection} selection
// @param {module:engine/model/schema~Schema} schema
// @returns {Boolean}
function selectionContainsOnlyMultipleObjects( selection, schema ) {
// It doesn't contain multiple objects if there is only one range.
if ( selection.rangeCount <= 1 ) {
if ( selection.rangeCount === 1 ) {
return false;
}

for ( const range of selection.getRanges() ) {
return [ ...selection.getRanges() ].every( range => {
const element = range.getContainedElement();

if ( !element || !schema.isObject( element ) ) {
return false;
}
}

return true;
return element && schema.isObject( element );
} );
}

/**
Expand Down

0 comments on commit 9e18fc7

Please sign in to comment.