MCPcopy Index your code
hub / github.com/codex-team/editor.js / delete

Method delete

src/components/modules/api/blocks.ts:162–189  ·  view source on GitHub ↗

* Deletes Block * * @param {number} blockIndex - index of Block to delete

(blockIndex: number = this.Editor.BlockManager.currentBlockIndex)

Source from the content-addressed store, hash-verified

160 * @param {number} blockIndex - index of Block to delete
161 */
162 public delete(blockIndex: number = this.Editor.BlockManager.currentBlockIndex): void {
163 try {
164 const block = this.Editor.BlockManager.getBlockByIndex(blockIndex);
165
166 this.Editor.BlockManager.removeBlock(block);
167 } catch (e) {
168 _.logLabeled(e, 'warn');
169
170 return;
171 }
172
173 /**
174 * in case of last block deletion
175 * Insert the new default empty block
176 */
177 if (this.Editor.BlockManager.blocks.length === 0) {
178 this.Editor.BlockManager.insert();
179 }
180
181 /**
182 * After Block deletion currentBlock is updated
183 */
184 if (this.Editor.BlockManager.currentBlock) {
185 this.Editor.Caret.setToBlock(this.Editor.BlockManager.currentBlock, this.Editor.Caret.positions.END);
186 }
187
188 this.Editor.Toolbar.close();
189 }
190
191 /**
192 * Clear Editor's area

Callers 1

methodsMethod · 0.95

Calls 5

removeBlockMethod · 0.80
getBlockByIndexMethod · 0.65
insertMethod · 0.65
setToBlockMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected