el-text-editor 0.0.72 → 0.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -640,7 +640,7 @@ class ElTextEditorComponent {
640
640
  }
641
641
  let editor = document.getElementById('editor');
642
642
  if (editor) {
643
- this.setCaretToEnd(editor);
643
+ this.moveCaretToEnd(editor);
644
644
  }
645
645
  this.placeHolderRemove.emit();
646
646
  }
@@ -665,7 +665,7 @@ class ElTextEditorComponent {
665
665
  // Set up a MutationObserver to handle content changes
666
666
  this.setupMutationObserver(editor);
667
667
  // Move the caret to the end after initial content setup
668
- this.setCaretToEnd(editor);
668
+ this.moveCaretToEnd(editor);
669
669
  // Track caret position on mouse click
670
670
  editor.addEventListener('click', () => {
671
671
  if (editor) { // Ensure editor is not null
@@ -689,21 +689,29 @@ class ElTextEditorComponent {
689
689
  setupMutationObserver(editor) {
690
690
  const observer = new MutationObserver(() => {
691
691
  // Move the caret to the end after content changes
692
- // this.moveCaretToEnd(editor);
692
+ this.moveCaretToEnd(editor);
693
693
  // Update model with the current content
694
694
  this.onModelChange(editor.innerHTML);
695
695
  });
696
696
  observer.observe(editor, { childList: true, subtree: true, characterData: true });
697
697
  }
698
698
  moveCaretToEnd(editor) {
699
+ // const selection = window.getSelection();
700
+ // const range = document.createRange();
701
+ // if (editor.lastChild) {
702
+ // range.selectNodeContents(editor);
703
+ // range.collapse(false); // Collapse to the end
704
+ // selection?.removeAllRanges();
705
+ // selection?.addRange(range);
706
+ // }
699
707
  const selection = window.getSelection();
700
- const range = document.createRange();
701
- if (editor.lastChild) {
702
- range.selectNodeContents(editor);
703
- range.collapse(false); // Collapse to the end
704
- selection?.removeAllRanges();
705
- selection?.addRange(range);
708
+ if (selection?.rangeCount) {
709
+ const range = selection.getRangeAt(0);
710
+ if (editor.contains(range.commonAncestorContainer)) {
711
+ return range.cloneRange(); // Return the current caret range
712
+ }
706
713
  }
714
+ return null;
707
715
  }
708
716
  // init_Func(html: any) {
709
717
  // if (html) {