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

Method clear

src/components/modules/blockManager.ts:894–918  ·  view source on GitHub ↗

* Clears Editor * * @param {boolean} needToAddDefaultBlock - 1) in internal calls (for example, in api.blocks.render) * we don't need to add an empty default block * 2) in api.blocks.clear we should add em

(needToAddDefaultBlock = false)

Source from the content-addressed store, hash-verified

892 * 2) in api.blocks.clear we should add empty block
893 */
894 public async clear(needToAddDefaultBlock = false): Promise<void> {
895 const queue = new PromiseQueue();
896
897 // Create a copy of the blocks array to avoid issues with array modification during iteration
898 const blocksToRemove = [...this.blocks];
899
900 blocksToRemove.forEach((block) => {
901 queue.add(async () => {
902 await this.removeBlock(block, false);
903 });
904 });
905
906 await queue.completed;
907
908 this.unsetCurrentBlock();
909
910 if (needToAddDefaultBlock) {
911 this.insert();
912 }
913
914 /**
915 * Add empty modifier
916 */
917 this.Editor.UI.checkEmptiness();
918 }
919
920 /**
921 * Cleans up all the block tools' resources

Callers

nothing calls this directly

Calls 6

addMethod · 0.95
removeBlockMethod · 0.95
unsetCurrentBlockMethod · 0.95
insertMethod · 0.95
forEachMethod · 0.80
checkEmptinessMethod · 0.80

Tested by

no test coverage detected