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.
@@ -642,7 +642,7 @@ class ElTextEditorComponent {
|
|
642
642
|
}
|
643
643
|
let editor = document.getElementById('editor');
|
644
644
|
if (editor) {
|
645
|
-
this.
|
645
|
+
this.moveCaretToEnd(editor);
|
646
646
|
}
|
647
647
|
this.placeHolderRemove.emit();
|
648
648
|
}
|
@@ -667,7 +667,7 @@ class ElTextEditorComponent {
|
|
667
667
|
// Set up a MutationObserver to handle content changes
|
668
668
|
this.setupMutationObserver(editor);
|
669
669
|
// Move the caret to the end after initial content setup
|
670
|
-
this.
|
670
|
+
this.moveCaretToEnd(editor);
|
671
671
|
// Track caret position on mouse click
|
672
672
|
editor.addEventListener('click', () => {
|
673
673
|
if (editor) { // Ensure editor is not null
|
@@ -691,21 +691,29 @@ class ElTextEditorComponent {
|
|
691
691
|
setupMutationObserver(editor) {
|
692
692
|
const observer = new MutationObserver(() => {
|
693
693
|
// Move the caret to the end after content changes
|
694
|
-
|
694
|
+
this.moveCaretToEnd(editor);
|
695
695
|
// Update model with the current content
|
696
696
|
this.onModelChange(editor.innerHTML);
|
697
697
|
});
|
698
698
|
observer.observe(editor, { childList: true, subtree: true, characterData: true });
|
699
699
|
}
|
700
700
|
moveCaretToEnd(editor) {
|
701
|
+
// const selection = window.getSelection();
|
702
|
+
// const range = document.createRange();
|
703
|
+
// if (editor.lastChild) {
|
704
|
+
// range.selectNodeContents(editor);
|
705
|
+
// range.collapse(false); // Collapse to the end
|
706
|
+
// selection?.removeAllRanges();
|
707
|
+
// selection?.addRange(range);
|
708
|
+
// }
|
701
709
|
const selection = window.getSelection();
|
702
|
-
|
703
|
-
|
704
|
-
range.
|
705
|
-
|
706
|
-
|
707
|
-
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
710
|
+
if (selection === null || selection === void 0 ? void 0 : selection.rangeCount) {
|
711
|
+
const range = selection.getRangeAt(0);
|
712
|
+
if (editor.contains(range.commonAncestorContainer)) {
|
713
|
+
return range.cloneRange(); // Return the current caret range
|
714
|
+
}
|
708
715
|
}
|
716
|
+
return null;
|
709
717
|
}
|
710
718
|
// init_Func(html: any) {
|
711
719
|
// if (html) {
|