Retrieve line number of string in Ace Editor
问题 I'm trying to retrieve the line number of a given string in the text displayed in the ace editor. Example: searching for "foo" Return: [ 4, 5 ] Condition: Line 4 and 5 in the content of the ace editor contains the "foo" string 回答1: Iterate over all lines and check indexOf function findFooLineNumbers(editor, foo) { var lines = editor.session.doc.getAllLines() var fooLineNumbers = [] for (var i = 0, l = lines.length; i < l; i++) { if (lines[i].indexOf(foo) != -1) fooLineNumbers.push(i) } return