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

Method insertMany

src/components/blocks.ts:248–278  ·  view source on GitHub ↗

* Inserts several blocks at once * * @param blocks - blocks to insert * @param index - index to insert blocks at

(blocks: Block[], index: number )

Source from the content-addressed store, hash-verified

246 * @param index - index to insert blocks at
247 */
248 public insertMany(blocks: Block[], index: number ): void {
249 const fragment = new DocumentFragment();
250
251 for (const block of blocks) {
252 fragment.appendChild(block.holder);
253 }
254
255 if (this.length > 0) {
256 if (index > 0) {
257 const previousBlockIndex = Math.min(index - 1, this.length - 1);
258 const previousBlock = this.blocks[previousBlockIndex];
259
260 previousBlock.holder.after(fragment);
261 } else if (index === 0) {
262 this.workingArea.prepend(fragment);
263 }
264
265 /**
266 * Insert blocks to the array at the specified index
267 */
268 this.blocks.splice(index, 0, ...blocks);
269 } else {
270 this.blocks.push(...blocks);
271 this.workingArea.appendChild(fragment);
272 }
273
274 /**
275 * Call Rendered event for each block
276 */
277 blocks.forEach((block) => block.call(BlockToolAPI.RENDERED));
278 }
279
280 /**
281 * Remove block

Callers

nothing calls this directly

Calls 4

prependMethod · 0.80
forEachMethod · 0.80
callMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected