admin管理员组文章数量:1336598
i got a problem with ace.js. I need to select a word an then insert the word without the occurance of =. This is my code:
editor.$search.setOptions({needle: '[A-z,0-9,_,\-]*="[A-z,0-9,_,\-,.]*"', regExp:true});
ranges = editor.$search.findAll(editor.session);
randomRange = ranges[Math.floor(Math.random() * ranges.length)];
if (randomRange){
editor.selection.setRange(randomRange);
var content = editor.session.getTextRange(editor.getSelectionRange());
alert(content);
var result = content.replace('=', '');
alert(result);
editor.replace(result);
}
It selects a random occurance of that text. Then i replace the = with a space. But ace.js always replaces the text with the second occurance of the matched element, not with the first selected. Any suggestions? TY!
UPDATE: example:
<?xml version="1.0"?>
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
it selects version="1.0", deletes the =. then it´s version"1.0"
but now when i call the function editor.replace(result), it replaces PurchaseOrderNumber="99503" with that text so then its:
<?xml version="1.0"?>
<PurchaseOrder version"1.0" OrderDate="1999-10-20">
i got a problem with ace.js. I need to select a word an then insert the word without the occurance of =. This is my code:
editor.$search.setOptions({needle: '[A-z,0-9,_,\-]*="[A-z,0-9,_,\-,.]*"', regExp:true});
ranges = editor.$search.findAll(editor.session);
randomRange = ranges[Math.floor(Math.random() * ranges.length)];
if (randomRange){
editor.selection.setRange(randomRange);
var content = editor.session.getTextRange(editor.getSelectionRange());
alert(content);
var result = content.replace('=', '');
alert(result);
editor.replace(result);
}
It selects a random occurance of that text. Then i replace the = with a space. But ace.js always replaces the text with the second occurance of the matched element, not with the first selected. Any suggestions? TY!
UPDATE: example:
<?xml version="1.0"?>
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
it selects version="1.0", deletes the =. then it´s version"1.0"
but now when i call the function editor.replace(result), it replaces PurchaseOrderNumber="99503" with that text so then its:
<?xml version="1.0"?>
<PurchaseOrder version"1.0" OrderDate="1999-10-20">
Share
Improve this question
asked Jun 16, 2014 at 8:46
m1crdym1crdy
1,4012 gold badges26 silver badges60 bronze badges
1 Answer
Reset to default 10GOT IT! this should be the replace statement:
editor.session.replace(editor.selection.getRange(), result);
本文标签: javascriptAce js replace textStack Overflow
版权声明:本文标题:javascript - Ace js replace text - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742374935a2462973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论