How can I fix the cursor problem in text editor

Viewed 107

I am working on text editor if I enter a word with wrong spellings. whenever I correct the misspelled word and I am on current position where I am fixing the spelling mistake after removing one letter of misspelled word it took me back again to the previous position or you can say at the end of the statement. How can I fix this problem?

public moveCaret(win, chars) {
    var sel, range;
    // word_count chars
    sel = window.getSelection();
    if (sel) {
        sel = win.getSelection();
        if (sel.character > 0) {
            var word_count = sel.focusNode;
            var newOffset = sel.focusOffset + chars;
            sel.collapse(word_count, Math.min(word_count.length, newOffset));
            console.log(newOffset, 'new')
        }
    } else if ( (sel = win.document.selection) ) {
        if (sel.type != "Control") {
            range = sel.createRange();
            range.move("character", chars);
            range.select();
        }
    }
}

enter image description here

0 Answers
Related