|
|
@@ -45,7 +45,7 @@ export default class BlockQuoteCommand extends Command {
|
|
|
const schema = model.schema;
|
|
|
const selection = model.document.selection;
|
|
|
|
|
|
- const blocks = getTopMostBlocks( selection, schema );
|
|
|
+ const blocks = Array.from( selection.getTopMostBlocks() );
|
|
|
|
|
|
model.change( writer => {
|
|
|
if ( this.value ) {
|
|
|
@@ -69,10 +69,9 @@ export default class BlockQuoteCommand extends Command {
|
|
|
* @returns {Boolean} The current value.
|
|
|
*/
|
|
|
_getValue() {
|
|
|
- const schema = this.editor.model.schema;
|
|
|
const selection = this.editor.model.document.selection;
|
|
|
|
|
|
- const firstBlock = getTopMostBlocks( selection, schema ).shift();
|
|
|
+ const firstBlock = first( selection.getTopMostBlocks() );
|
|
|
|
|
|
// In the current implementation, the block quote must be an immediate parent of a block element.
|
|
|
return !!( firstBlock && findQuote( firstBlock ) );
|
|
|
@@ -227,48 +226,3 @@ function checkCanBeQuoted( schema, block ) {
|
|
|
|
|
|
return isBQAllowed && isBlockAllowedInBQ;
|
|
|
}
|
|
|
-
|
|
|
-// Returns top-level block elements from selected blocks.
|
|
|
-//
|
|
|
-// For given selection:
|
|
|
-//
|
|
|
-// [<blockA></blockA>
|
|
|
-// <blockB>
|
|
|
-// <blockC></blockC>
|
|
|
-// <blockD></blockD>
|
|
|
-// </blockB>
|
|
|
-// <blockE></blockE>]
|
|
|
-//
|
|
|
-// This method will only return blocks: A, B & E.
|
|
|
-//
|
|
|
-// @param {module:engine/model/selection~Selection} selection
|
|
|
-// @param {module:engine/model/schema~Schema} schema
|
|
|
-// @returns {module:engine/model/element~Element[]}
|
|
|
-function getTopMostBlocks( selection, schema ) {
|
|
|
- const topMostBlocks = Array.from( selection.getSelectedBlocks() )
|
|
|
- .filter( block => {
|
|
|
- const parentBlock = findAncestorBlock( block, schema );
|
|
|
-
|
|
|
- // Filter out blocks that are nested in other selected blocks (like paragraphs in tables).
|
|
|
- return !parentBlock || !Array.from( selection.getSelectedBlocks() ).includes( parentBlock );
|
|
|
- } );
|
|
|
-
|
|
|
- return topMostBlocks;
|
|
|
-}
|
|
|
-
|
|
|
-// Returns first ancestor block of a node.
|
|
|
-//
|
|
|
-// @param {module:engine/model/node~Node} node
|
|
|
-// @param {module:engine/model/schema~Schema} schema
|
|
|
-// @returns {module:engine/model/node~Node|undefined}
|
|
|
-function findAncestorBlock( node, schema ) {
|
|
|
- let parent = node.parent;
|
|
|
-
|
|
|
- while ( parent ) {
|
|
|
- if ( schema.isBlock( parent ) ) {
|
|
|
- return parent;
|
|
|
- }
|
|
|
-
|
|
|
- parent = parent.parent;
|
|
|
- }
|
|
|
-}
|