Angular 如何将搜索结果的计数添加到codemirror中

Angular 如何将搜索结果的计数添加到codemirror中,angular,typescript,codemirror,Angular,Typescript,Codemirror,在我做了一些关于如何向codemirror添加搜索结果计数的搜索之后,我没有找到任何东西,我正在处理angular,我使用了ngx codemirror,所以我发现唯一的方法是编辑ngx codemirror包中的search.js 我需要寻找一种更好的方法,因为如果我改变包中的search.js文件,这会有点糟糕,因为我们在一个团队中工作,每天都有很多推送,我们不能每次推送node_模块 角度传感器的解决方案: 注意:请记住,这不是最好的解决方案 (无需编辑code镜像package) HTM

在我做了一些关于如何向codemirror添加搜索结果计数的搜索之后,我没有找到任何东西,我正在处理angular,我使用了ngx codemirror,所以我发现唯一的方法是编辑ngx codemirror包中的search.js

我需要寻找一种更好的方法,因为如果我改变包中的search.js文件,这会有点糟糕,因为我们在一个团队中工作,每天都有很多推送,我们不能每次推送node_模块

角度传感器的解决方案: 注意:请记住,这不是最好的解决方案 (无需编辑
code镜像
package)

HTML:

搜索量:{{resultCount}
打字稿:
导出类htmleditor组件
多切克{
@ViewChild(“codeEditor”)codeEditor:CodemirrorComponent;
结果计数=0;
htmlString='';
构造函数(){}
ngDoCheck(){
如果(
这个是.codeditor&&
这个是.codeEditor.codemirr&&
this.htmlString.length>0
) {
这是checkSearch();
}
}
checkSearch(){
const searchField=document.getElementsByClassName(
“CodeMirror搜索字段”
)[0]如有;
if(searchField&&searchField.value.length>0){
const text=new RegExp(searchField.value,'gi');
常量计数=(this.htmlString.match(text)| |[]).length;
this.resultCount=count;
}否则{
this.resultCount=0;
}
}
}
现在尝试按住CTRL+F键打开
codemirr
,您将看到搜索计数

现场演示: