el-text-editor 0.0.70 → 0.0.72
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.
- package/esm2020/lib/el-text-editor.component.mjs +3 -50
- package/fesm2015/el-text-editor.mjs +2 -49
- package/fesm2015/el-text-editor.mjs.map +1 -1
- package/fesm2020/el-text-editor.mjs +2 -49
- package/fesm2020/el-text-editor.mjs.map +1 -1
- package/lib/el-text-editor.component.d.ts +0 -2
- package/package.json +1 -1
@@ -640,9 +640,7 @@ class ElTextEditorComponent {
|
|
640
640
|
}
|
641
641
|
let editor = document.getElementById('editor');
|
642
642
|
if (editor) {
|
643
|
-
this.
|
644
|
-
this.onEditorClick(editor);
|
645
|
-
this.onKeyboardMove(editor);
|
643
|
+
this.setCaretToEnd(editor);
|
646
644
|
}
|
647
645
|
this.placeHolderRemove.emit();
|
648
646
|
}
|
@@ -667,9 +665,7 @@ class ElTextEditorComponent {
|
|
667
665
|
// Set up a MutationObserver to handle content changes
|
668
666
|
this.setupMutationObserver(editor);
|
669
667
|
// Move the caret to the end after initial content setup
|
670
|
-
this.
|
671
|
-
this.onEditorClick(editor);
|
672
|
-
this.onKeyboardMove(editor);
|
668
|
+
this.setCaretToEnd(editor);
|
673
669
|
// Track caret position on mouse click
|
674
670
|
editor.addEventListener('click', () => {
|
675
671
|
if (editor) { // Ensure editor is not null
|
@@ -699,16 +695,6 @@ class ElTextEditorComponent {
|
|
699
695
|
});
|
700
696
|
observer.observe(editor, { childList: true, subtree: true, characterData: true });
|
701
697
|
}
|
702
|
-
// private moveCaretToEnd(editor: HTMLElement) {
|
703
|
-
// const selection = window.getSelection();
|
704
|
-
// const range = document.createRange();
|
705
|
-
// if (editor.lastChild) {
|
706
|
-
// range.selectNodeContents(editor);
|
707
|
-
// range.collapse(false); // Collapse to the end
|
708
|
-
// selection?.removeAllRanges();
|
709
|
-
// selection?.addRange(range);
|
710
|
-
// }
|
711
|
-
// }
|
712
698
|
moveCaretToEnd(editor) {
|
713
699
|
const selection = window.getSelection();
|
714
700
|
const range = document.createRange();
|
@@ -719,39 +705,6 @@ class ElTextEditorComponent {
|
|
719
705
|
selection?.addRange(range);
|
720
706
|
}
|
721
707
|
}
|
722
|
-
onKeyboardMove(editor) {
|
723
|
-
editor.addEventListener('keydown', (event) => {
|
724
|
-
const selection = window.getSelection();
|
725
|
-
const range = document.createRange();
|
726
|
-
if (selection && selection.rangeCount > 0) {
|
727
|
-
const currentRange = selection.getRangeAt(0);
|
728
|
-
const currentCaretPosition = currentRange.startContainer;
|
729
|
-
if (event.key === 'ArrowRight' || event.key === 'ArrowLeft' || event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
730
|
-
// You can handle specific behavior for different arrow keys here
|
731
|
-
// For example, move caret within a specific node or across nodes
|
732
|
-
}
|
733
|
-
}
|
734
|
-
});
|
735
|
-
}
|
736
|
-
onEditorClick(editor) {
|
737
|
-
editor.addEventListener('click', (event) => {
|
738
|
-
const selection = window.getSelection();
|
739
|
-
const range = document.createRange();
|
740
|
-
const clickedNode = event.target;
|
741
|
-
if (clickedNode && clickedNode !== editor) {
|
742
|
-
// Place the caret at the clicked position
|
743
|
-
range.setStart(clickedNode, 0);
|
744
|
-
range.setEnd(clickedNode, clickedNode?.length);
|
745
|
-
}
|
746
|
-
else {
|
747
|
-
// Move caret to the end if clicked inside the editor but not on text node
|
748
|
-
range.selectNodeContents(editor);
|
749
|
-
range.collapse(false);
|
750
|
-
}
|
751
|
-
selection?.removeAllRanges();
|
752
|
-
selection?.addRange(range);
|
753
|
-
});
|
754
|
-
}
|
755
708
|
// init_Func(html: any) {
|
756
709
|
// if (html) {
|
757
710
|
// let editor = document.getElementById('editor');
|