// rtwsCodeMirror 为你的编辑器实例
//定义需要高亮的关键字keywords
const keywords={
'hello':'red',
'world':'blue',
};
const reg = new RegExp("\\b("+Object.keys(keywords).join('|')+")\\b","g");
//这一步清除之前的关键字标记,可要可不要
rtwsCodeMirror.operation(function () {
for (let mark of rtwsCodeMirror.getAllMarks()){
mark.clear();
}
});
//重要部分
rtwsCodeMirror.operation(function () {
let cursor = rtwsCodeMirror.getCursor();
let doc = rtwsCodeMirror.getDoc();
let text = rtwsCodeMirror.getValue();
// 正则过滤
let matches = text.match(reg);
if(matches){
matches.forEach((match)=>{
let color = keywords[match];
let index = text.indexOf(match,cursor,ch);
while