MCPcopy
hub / github.com/codex-team/editor.js / removeBlock

Method removeBlock

src/components/modules/blockManager.ts:525–565  ·  view source on GitHub ↗

* Remove passed Block * * @param block - Block to remove * @param addLastBlock - if true, adds new default block at the end. @todo remove this logic and use event-bus instead

(block: Block, addLastBlock = true)

Source from the content-addressed store, hash-verified

523 * @param addLastBlock - if true, adds new default block at the end. @todo remove this logic and use event-bus instead
524 */
525 public removeBlock(block: Block, addLastBlock = true): Promise<void> {
526 return new Promise((resolve) => {
527 const index = this._blocks.indexOf(block);
528
529 /**
530 * If index is not passed and there is no block selected, show a warning
531 */
532 if (!this.validateIndex(index)) {
533 throw new Error('Can\'t find a Block to remove');
534 }
535
536 this._blocks.remove(index);
537 block.destroy();
538
539 /**
540 * Force call of didMutated event on Block removal
541 */
542 this.blockDidMutated(BlockRemovedMutationType, block, {
543 index,
544 });
545
546 if (this.currentBlockIndex >= index) {
547 this.currentBlockIndex--;
548 }
549
550 /**
551 * If first Block was removed, insert new Initial Block and set focus on it`s first input
552 */
553 if (!this.blocks.length) {
554 this.unsetCurrentBlock();
555
556 if (addLastBlock) {
557 this.insert();
558 }
559 } else if (index === 0) {
560 this.currentBlockIndex = 0;
561 }
562
563 resolve();
564 });
565 }
566
567 /**
568 * Remove only selected Blocks

Callers 6

mergeBlocksMethod · 0.95
removeSelectedBlocksMethod · 0.95
clearMethod · 0.95
backspaceMethod · 0.80
deleteMethod · 0.80
deleteMethod · 0.80

Calls 7

validateIndexMethod · 0.95
blockDidMutatedMethod · 0.95
unsetCurrentBlockMethod · 0.95
insertMethod · 0.95
indexOfMethod · 0.80
destroyMethod · 0.65
removeMethod · 0.45

Tested by

no test coverage detected