Javascript 如何根据codemirror中的子字符串获取行号?

Javascript 如何根据codemirror中的子字符串获取行号?,javascript,codemirror,Javascript,Codemirror,我需要在有codemirror插件的textarea中获取特定字符串的行号 var editor= CodeMirror.fromTextArea(document.getElementById("refstyle"); var doc = editor.getDoc(); var cursor = doc.getCursor(); // gets the line number in the cursor position var line = doc.getLine(cursor.li

我需要在有codemirror插件的textarea中获取特定字符串的行号

var editor= CodeMirror.fromTextArea(document.getElementById("refstyle");  

var doc = editor.getDoc();
var cursor = doc.getCursor(); // gets the line number in the cursor position
var line = doc.getLine(cursor.line); // get the line contents 
editor.getSelection(line number)   //it will select the text based on line number
那么,如何根据字符串(我希望类似doc.getLine(字符串)或doc.getSelection(字符串))获取行号呢


是否有任何函数可以根据字符串获取行号,或根据文本区域中的行号选择搜索的字符串?请帮忙

要在CodeMirror实例中搜索,请使用插件。它将为您提供匹配的行/字符位置。

要在CodeMirror实例中搜索,请使用插件。它将为您提供匹配的行/字符位置。

请查看
http://codemirror.net/demo/search.html
您需要添加附加的addon js文件以实现搜索功能请查看
http://codemirror.net/demo/search.html
您需要添加附加的加载项js文件以实现搜索功能我认为这是一个有效的回答@维迪亚·拉朱。欢迎来到堆栈溢出!如果您有解决方案,请勾选此答案。谢谢:)我认为这是一个有效的答案@维迪亚·拉朱。欢迎来到堆栈溢出!如果您有解决方案,请勾选此答案。谢谢:)例如