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
Add a ment  | 

1 Answer 1

Reset to default 10

GOT IT! this should be the replace statement:

editor.session.replace(editor.selection.getRange(), result);   

本文标签: javascriptAce js replace textStack Overflow