I’m using a custom search replace interface and I’m having a problem with the marks on scrollbar feature. If I replace matches manually the marks on the scrollbar disappear as I go along but if I use my replace all feature with a while loop the last mark is not cleared unless I clear the matches array in cm.showMatchesOnScrollbar() right after the loop
ToolBars.prototype.replaceAll = function(e) {
e.preventDefault()
var cm = this.cm;
var tools = this;
cm.operation(function() {
var elt = e.target;
tools.cursor = cm.getSearchCursor(tools.query, {line:0, ch:0}, tools.caseFold);
var replaceText = tools.elt.replaceText.value;
var found, from, to, textFound, newText
while (found = tools.cursor.findNext()) {
textFound = cm.getRange(tools.cursor.from(), tools.cursor.to());
newText = typeof tools.query == "string" ? replaceText : textFound.replace(tools.query, replaceText) ;
tools.cursor.replace(""); // clear old mark
tools.cursor.replace(newText);
tools.markRP.push(cm.markText(tools.cursor.from(), tools.cursor.to(), {className: "CodeMirror-markReplaced"}));
}
tools.markScroll.matches = [];
tools.searchControls1.forEach(function(button) {
button.disabled = true;
});
tools.allReplace = true;
tools.cursor = null;
elt.blur();
});
}
tools.markScroll is the object returned by showMatchesOnScrollbar(). Clearing the matches array gets the job done ordinarily, but if I undo then redo I get the lingering match left behind.
Is there a way to get the last mark cleared without clearing the matches array after the loop?