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.