I'm working on a "text-checker" while using Mark.js.
The issue I am having is, that once I input the word and it gets marked/highlighted the cursor jumps to the beginning of that word. Here is an example.
Maybe the solution would be to somehow save the cursor location before the markup is triggered and loading it once the markup is done? Since I don't know when the markup is triggered maybe, save cursor location on every input and loading again index+1?
Any help, pointers, reference would be welcome.
Thank you
<div class="textarea" id="textarea" contenteditable="true">
I hate blood pudding and so do you.
</div>
.red { background-color: lightcoral; }
.green{ background-color: lightgreen; }
.brown{ background-color: burlywood; }
var textarea = document.getElementById("textarea");
var instance = new Mark("div.textarea");
var red = ["red", "blood"];
var brown = ["brown", "pudding"];
var green = ["green", "grass"];
var markWords = function() {
instance.mark(red, {
seperateWordSearch: false,
className: "red",
"accuracy": {
"value": "exactly",
"limiters": [",", ".", "!", "?"]
}
});
instance.mark(brown, {
seperateWordSearch: false,
className: "brown",
"accuracy": {
"value": "exactly",
"limiters": [",", ".", "!", "?"]
}
});
instance.mark(green, {
seperateWordSearch: false,
className: "green",
"accuracy": {
"value": "exactly",
"limiters": [",", ".", "!", "?"]
}
});
}
markWords();
textarea.addEventListener("input", markWords);
A big shout out @mcernak for helping me get to this point.