el-text-editor 0.0.70 → 0.0.71
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 +11 -58
- package/fesm2015/el-text-editor.mjs +10 -57
- package/fesm2015/el-text-editor.mjs.map +1 -1
- package/fesm2020/el-text-editor.mjs +10 -57
- package/fesm2020/el-text-editor.mjs.map +1 -1
- package/lib/el-text-editor.component.d.ts +1 -3
- package/package.json +1 -1
@@ -643,23 +643,21 @@ class ElTextEditorComponent {
|
|
643
643
|
let editor = document.getElementById('editor');
|
644
644
|
if (editor) {
|
645
645
|
this.moveCaretToEnd(editor);
|
646
|
-
this.onEditorClick(editor);
|
647
|
-
this.onKeyboardMove(editor);
|
648
646
|
}
|
649
647
|
this.placeHolderRemove.emit();
|
650
648
|
}
|
651
649
|
}
|
652
650
|
// // Move caret to the end of the editor content
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
651
|
+
moveCaretToEnd(editor) {
|
652
|
+
const selection = window.getSelection();
|
653
|
+
const range = document.createRange();
|
654
|
+
if (editor.lastChild) {
|
655
|
+
range.selectNodeContents(editor);
|
656
|
+
range.collapse(false); // Collapse to the end
|
657
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
658
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
659
|
+
}
|
660
|
+
}
|
663
661
|
init_Func(html) {
|
664
662
|
if (html) {
|
665
663
|
let editor = document.getElementById('editor');
|
@@ -670,8 +668,6 @@ class ElTextEditorComponent {
|
|
670
668
|
this.setupMutationObserver(editor);
|
671
669
|
// Move the caret to the end after initial content setup
|
672
670
|
this.moveCaretToEnd(editor);
|
673
|
-
this.onEditorClick(editor);
|
674
|
-
this.onKeyboardMove(editor);
|
675
671
|
// Track caret position on mouse click
|
676
672
|
editor.addEventListener('click', () => {
|
677
673
|
if (editor) { // Ensure editor is not null
|
@@ -711,49 +707,6 @@ class ElTextEditorComponent {
|
|
711
707
|
// selection?.addRange(range);
|
712
708
|
// }
|
713
709
|
// }
|
714
|
-
moveCaretToEnd(editor) {
|
715
|
-
const selection = window.getSelection();
|
716
|
-
const range = document.createRange();
|
717
|
-
if (editor.lastChild) {
|
718
|
-
range.selectNodeContents(editor);
|
719
|
-
range.collapse(false); // Collapse to the end
|
720
|
-
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
721
|
-
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
722
|
-
}
|
723
|
-
}
|
724
|
-
onKeyboardMove(editor) {
|
725
|
-
editor.addEventListener('keydown', (event) => {
|
726
|
-
const selection = window.getSelection();
|
727
|
-
const range = document.createRange();
|
728
|
-
if (selection && selection.rangeCount > 0) {
|
729
|
-
const currentRange = selection.getRangeAt(0);
|
730
|
-
const currentCaretPosition = currentRange.startContainer;
|
731
|
-
if (event.key === 'ArrowRight' || event.key === 'ArrowLeft' || event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
732
|
-
// You can handle specific behavior for different arrow keys here
|
733
|
-
// For example, move caret within a specific node or across nodes
|
734
|
-
}
|
735
|
-
}
|
736
|
-
});
|
737
|
-
}
|
738
|
-
onEditorClick(editor) {
|
739
|
-
editor.addEventListener('click', (event) => {
|
740
|
-
const selection = window.getSelection();
|
741
|
-
const range = document.createRange();
|
742
|
-
const clickedNode = event.target;
|
743
|
-
if (clickedNode && clickedNode !== editor) {
|
744
|
-
// Place the caret at the clicked position
|
745
|
-
range.setStart(clickedNode, 0);
|
746
|
-
range.setEnd(clickedNode, clickedNode === null || clickedNode === void 0 ? void 0 : clickedNode.length);
|
747
|
-
}
|
748
|
-
else {
|
749
|
-
// Move caret to the end if clicked inside the editor but not on text node
|
750
|
-
range.selectNodeContents(editor);
|
751
|
-
range.collapse(false);
|
752
|
-
}
|
753
|
-
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
754
|
-
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
755
|
-
});
|
756
|
-
}
|
757
710
|
// init_Func(html: any) {
|
758
711
|
// if (html) {
|
759
712
|
// let editor = document.getElementById('editor');
|