[英]How to get the line number based on substring in 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.line); // get the line contents
editor.getSelection(line number) //it will select the text based on line number
因此,如何獲取基於字符串的行號(我希望像doc.getLine(string)或doc.getSelection(String)之類的東西)
是否有任何功能可基於字符串獲取行號或基於textarea中基於行號選擇的搜索字符串? 請幫助!
要在CodeMirror實例內部進行搜索,請使用searchcursor
插件。 它會給您匹配的行/字符位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.