简体   繁体   English

如何在Codemirror中基于子字符串获取行号?

[英]How to get the line number based on substring in codemirror?

I need to get the line number of specific string in the textarea which has codemirror plugin. 我需要在具有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

So, How can I get the line number based on string (I expect something like doc.getLine(string) or doc.getSelection(String)) 因此,如何获取基于字符串的行号(我希望像doc.getLine(string)或doc.getSelection(String)之类的东西)

Is there any function to get the line number based on the string or to get searched string selected based on line number in the textarea? 是否有任何功能可基于字符串获取行号或基于textarea中基于行号选择的搜索字符串? Pls help! 请帮助!

To search inside a CodeMirror instance, use the searchcursor addon. 要在CodeMirror实例内部进行搜索,请使用searchcursor插件。 It'll give you the line/char position of matches. 它会给您匹配的行/字符位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM