Objective: I am using codemirror as editor. I want to
- Search and highlight multiple strings
- I want to be able to iterate each number of matches found and print its line number.
- I want to do it programatically and do no want to use dialog as in example https://codemirror.net/demo/search.html
Issue:
- during while loop only last match is selected, previous ones are cleared , but i also want it hightlighted yellow like https://codemirror.net/demo/search.html
JSFIDDLE: https://jsfiddle.net/bababalcksheep/p7xg1utn/30/
CODE:
$(document).ready(function() {
//
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: "text/html",
lineNumbers: true,
});
//
function search(val) {
var cursor = editor.getSearchCursor(val);
while (cursor.findNext()) {
editor.setSelection(cursor.from(), cursor.to());
console.log('found at line ', cursor.pos.from.line + 1);
}
}
//
$('#search').click(function(event) {
event.preventDefault();
search(/^alpha|^beta/);
});
//
});