* 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)
| 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 |
nothing calls this directly
no test coverage detected