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.
@@ -642,9 +642,7 @@ class ElTextEditorComponent {
642
642
  }
643
643
  let editor = document.getElementById('editor');
644
644
  if (editor) {
645
- this.moveCaretToEnd(editor);
646
- this.onEditorClick(editor);
647
- this.onKeyboardMove(editor);
645
+ this.setCaretToEnd(editor);
648
646
  }
649
647
  this.placeHolderRemove.emit();
650
648
  }
@@ -669,9 +667,7 @@ class ElTextEditorComponent {
669
667
  // Set up a MutationObserver to handle content changes
670
668
  this.setupMutationObserver(editor);
671
669
  // Move the caret to the end after initial content setup
672
- this.moveCaretToEnd(editor);
673
- this.onEditorClick(editor);
674
- this.onKeyboardMove(editor);
670
+ this.setCaretToEnd(editor);
675
671
  // Track caret position on mouse click
676
672
  editor.addEventListener('click', () => {
677
673
  if (editor) { // Ensure editor is not null
@@ -701,16 +697,6 @@ class ElTextEditorComponent {
701
697
  });
702
698
  observer.observe(editor, { childList: true, subtree: true, characterData: true });
703
699
  }
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
- // }
714
700
  moveCaretToEnd(editor) {
715
701
  const selection = window.getSelection();
716
702
  const range = document.createRange();
@@ -721,39 +707,6 @@ class ElTextEditorComponent {
721
707
  selection === null || selection === void 0 ? void 0 : selection.addRange(range);
722
708
  }
723
709
  }
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');