Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught DOMException: Failed to execute 'setEnd' on 'Range': There is no child at offset 46. #116

Open
beoleg0 opened this issue Apr 30, 2021 · 0 comments

Comments

@beoleg0
Copy link

beoleg0 commented Apr 30, 2021

package.json

"@angular/core": "~7.2.0",
"ngx-summernote": "^0.6.2",
"summernote": "^0.8.16",
"jquery": "^3.4.1",

I created custom node that i inserted on button click. Button was added to toolbar. There is the code of node that I inserted

  @action insertCheckList() {
    const currentNode = this.getSelectionNode();
    const currentLi = currentNode.parentElement.closest('li');
    const editorContent = document.querySelector('.note-editable');

    if (currentLi) {
      const currentCheckList = currentLi.closest('.note-check-list');

      if (!currentCheckList) {
        return;
      }

      const items = currentCheckList.querySelectorAll('li');
      if (items.length === 1) {
        editorContent.removeChild(currentCheckList);
        (editorContent as HTMLInputElement).focus();
        setTimeout(() => this.moveCaret(0), 100);
      }
      return;
    }

    const container = document.createElement('ul');
    container.classList.add('note-check-list');
    container.innerHTML = '<li><span class="note-icon-check">' +
      '<span class="note-check-list-text"></span>' +
      '</span></li>';
    this.context.invoke('editor.restoreRange');
    this.context.invoke('editor.focus');
    this.context.invoke('editor.insertNode', container);
    this.moveCaret(0, '.note-check-list-text');

    const currentChecklist = (this.getSelectionNode() as HTMLElement).closest('.note-check-list');

    if (currentChecklist && currentChecklist.previousElementSibling && currentChecklist.previousElementSibling.textContent === '') {
      editorContent.removeChild(currentChecklist.previousElementSibling);
    }

    if (currentChecklist && currentChecklist.nextElementSibling && currentChecklist.nextElementSibling.textContent === '') {
      editorContent.removeChild(currentChecklist.nextElementSibling);
    }
  }

The error is throw after that I add custom node, select text of lines before and after node, and the node itself. After selecting I change selected nodes to ordered or unordered list and this error thows. How can I fix this?

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant