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

Method backspace

src/components/modules/blockEvents.ts:347–425  ·  view source on GitHub ↗

* Handle backspace keydown on Block * * @param {KeyboardEvent} event - keydown

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

345 * @param {KeyboardEvent} event - keydown
346 */
347 private backspace(event: KeyboardEvent): void {
348 const { BlockManager, Caret } = this.Editor;
349 const { currentBlock, previousBlock } = BlockManager;
350
351 if (currentBlock === undefined) {
352 return;
353 }
354
355 /**
356 * If some fragment is selected, leave native behaviour
357 */
358 if (!SelectionUtils.isCollapsed) {
359 return;
360 }
361
362 /**
363 * If caret is not at the start, leave native behaviour
364 */
365 if (!currentBlock.currentInput || !caretUtils.isCaretAtStartOfInput(currentBlock.currentInput)) {
366 return;
367 }
368 /**
369 * All the cases below have custom behaviour, so we don't need a native one
370 */
371 event.preventDefault();
372 this.Editor.Toolbar.close();
373
374 const isFirstInputFocused = currentBlock.currentInput === currentBlock.firstInput;
375
376 /**
377 * For example, caret at the start of the Quote second input (caption) — just navigate previous input
378 */
379 if (!isFirstInputFocused) {
380 Caret.navigatePrevious();
381
382 return;
383 }
384
385 /**
386 * Backspace at the start of the first Block should do nothing
387 */
388 if (previousBlock === null) {
389 return;
390 }
391
392 /**
393 * If prev Block is empty, it should be removed just like a character
394 */
395 if (previousBlock.isEmpty) {
396 BlockManager.removeBlock(previousBlock);
397
398 return;
399 }
400
401 /**
402 * If current Block is empty, just remove it and set cursor to the previous Block (like we're removing line break char)
403 */
404 if (currentBlock.isEmpty) {

Callers 1

keydownMethod · 0.95

Calls 6

mergeBlocksMethod · 0.95
areBlocksMergeableFunction · 0.90
navigatePreviousMethod · 0.80
removeBlockMethod · 0.80
closeMethod · 0.65
setToBlockMethod · 0.65

Tested by

no test coverage detected