简体   繁体   English

ace编辑器查找代码段

[英]ace editor find code snippet

i have setup ace to render html code let's say for example that he renderer the following code 我设置了ace来呈现html代码,例如,他渲染了以下代码

    1 <html>
    2 <body>
    3 <table>
    4 <tr>
    5 <td>
    6 test
    7 </td>

I would like to get the line number for a given fragment of my code, so for example if i search 我想获取给定代码片段的行号,例如,如果我搜索

"<html><body><table><tr><td>" 

i would like to move the cursor and higlight line 6. Unfortunately ace built in find function only seems to find code that are at the same line so 我想移动光标和高光6行。不幸的是,内置于find函数中的ace似乎只能找到同一行的代码,因此

ace.find('<html>', options) 

work and highlight line 1 but 工作并突出显示第1行,但

ace.find('<html><body>', options) 

doesn't find anything at all. 根本找不到任何东西。

Could you explain me why or give me a workaround ? 您能解释一下为什么还是给我解决方法? Thanks by advance ;) 预先感谢;)

if <html> and <body> are on different lines you need to search for ace.find('<html>\\n<body>', options) (with \\n ) 如果<html><body>在不同的行上,则需要搜索ace.find('<html>\\n<body>', options) (带有\\n

another way is to use regexp to find offset you want in the editor.getValue() string, and use 另一种方法是使用regexp在editor.getValue()字符串中查找所需的偏移量,然后使用

pos = session.doc.indexToPosition(100)
session.selection.moveToPosition(pos)

to move cursor to it 将光标移到它

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

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