Skip to content

[Bug] isAtStart throws an error when deleting content. #1179

@vincentdesmares

Description

@vincentdesmares

Sometimes when you delete content, a bug appears:

TypeError
Cannot read property 'length' of undefined

Error source:

{snip} tion(t){var e=d.default.isLineBreakTag(t),n=1===t.children.length&&d.default.isLineBreakTag(t.children[0]),o=e||n;return d.default.isEmpty(t {snip}

Which is the minified version of:

  const leftSiblings = this.getHigherLevelSiblings(focusNode as HTMLElement, 'left');
      const nothingAtLeft = leftSiblings.every((node) => {
        /**
         * Workaround case when block starts with several <br>'s (created by SHIFT+ENTER)
         *
         * @see https://github.com/codex-team/editor.js/issues/726
         * We need to allow to delete such linebreaks, so in this case caret IS NOT AT START
         */
        const regularLineBreak = $.isLineBreakTag(node);
        /**
         * Workaround SHIFT+ENTER in Safari, that creates <div><br></div> instead of <br>
         */
        const lineBreakInSafari = node.children.length === 1 && $.isLineBreakTag(node.children[0] as HTMLElement);
        const isLineBreak = regularLineBreak || lineBreakInSafari;

        return $.isEmpty(node) && !isLineBreak;
      });

Last action of the user:

div.ce-block__content > div.ce-paragraph.cdx-block

Expected behavior:

The deletion should work.

Device, Browser, OS: Chrome 83.0.4103, Mac OS X 10.14.6

Editor.js version:

    "@editorjs/checklist": "^1.1.0",
    "@editorjs/editorjs": "^2.17.0",
    "@editorjs/embed": "^2.3.1",
    "@editorjs/header": "^2.4.1",
    "@editorjs/image": "^2.3.4",
    "@editorjs/link": "^2.1.3",
    "@editorjs/list": "^1.4.0",
    "@editorjs/marker": "^1.2.2",
    "@editorjs/quote": "^2.3.0",
    "@editorjs/warning": "^1.1.1",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions