saveCaretPosition(element, index) {
    if (this.root?.focusedComponent?.path === this.path) {
      try {
        this.root.currentSelection = { selection: [element.selectionStart, element.selectionEnd], index };
      }
      catch (e) {
        if (!(e instanceof DOMException)) {
          console.debug(e);
        }
      }
    }
  }
/* Saves current caret position to restore it after the component is redrawn
@param {HTMLElement} element - The element to save the caret position for.
@param {number} index - The index of the element.