when I call the getSelection method, the cursor automatically moves to the top.

Hi,
I’m encountered with a strange problem, each time I call the function getSelection( ), my cursor is reset to 0th line.

the function is as follow

component.ts

    getSelection(event: MouseEvent) {
    const codeMirror = document.querySelector('.CodeMirror')['CodeMirror'];
    if (this.textSelectStatus) {
      let currentSelectedText = codeMirror.getSelection(); // find selected string
      currentSelectedText = currentSelectedText.trim();
      if (currentSelectedText.length > 2) {
        this.validateSelectedText(currentSelectedText);
      }
    }
    const cursorPosition = codeMirror.getCursor();
    console.log(cursorPosition);
    console.log(typeof cursorPosition['line']);
    codeMirror.focus();
    codeMirror.setCursor({ line: cursorPosition['line'], ch: 0});
  }

component.html

<codemirror *ngIf="!innerHtmlStatus" [(ngModel)]="choosedArticlePlaneText" [config]="config" (mouseup)="getSelection($event)" >
                        </codemirror>

even after I call the setCursor function, the cursor is not moving.

Nothing stands out in that code. If you can reproduce this in a minimal setup (without Angular and such), feel free to file an issue.