el-text-editor 0.0.69 → 0.0.70
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 +48 -1
- package/fesm2015/el-text-editor.mjs +47 -0
- package/fesm2015/el-text-editor.mjs.map +1 -1
- package/fesm2020/el-text-editor.mjs +47 -0
- package/fesm2020/el-text-editor.mjs.map +1 -1
- package/lib/el-text-editor.component.d.ts +2 -0
- package/package.json +1 -1
@@ -643,6 +643,8 @@ 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);
|
646
648
|
}
|
647
649
|
this.placeHolderRemove.emit();
|
648
650
|
}
|
@@ -668,6 +670,8 @@ class ElTextEditorComponent {
|
|
668
670
|
this.setupMutationObserver(editor);
|
669
671
|
// Move the caret to the end after initial content setup
|
670
672
|
this.moveCaretToEnd(editor);
|
673
|
+
this.onEditorClick(editor);
|
674
|
+
this.onKeyboardMove(editor);
|
671
675
|
// Track caret position on mouse click
|
672
676
|
editor.addEventListener('click', () => {
|
673
677
|
if (editor) { // Ensure editor is not null
|
@@ -697,6 +701,16 @@ class ElTextEditorComponent {
|
|
697
701
|
});
|
698
702
|
observer.observe(editor, { childList: true, subtree: true, characterData: true });
|
699
703
|
}
|
704
|
+
// private moveCaretToEnd(editor: HTMLElement) {
|
705
|
+
// const selection = window.getSelection();
|
706
|
+
// const range = document.createRange();
|
707
|
+
// if (editor.lastChild) {
|
708
|
+
// range.selectNodeContents(editor);
|
709
|
+
// range.collapse(false); // Collapse to the end
|
710
|
+
// selection?.removeAllRanges();
|
711
|
+
// selection?.addRange(range);
|
712
|
+
// }
|
713
|
+
// }
|
700
714
|
moveCaretToEnd(editor) {
|
701
715
|
const selection = window.getSelection();
|
702
716
|
const range = document.createRange();
|
@@ -707,6 +721,39 @@ class ElTextEditorComponent {
|
|
707
721
|
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
708
722
|
}
|
709
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
|
+
}
|
710
757
|
// init_Func(html: any) {
|
711
758
|
// if (html) {
|
712
759
|
// let editor = document.getElementById('editor');
|