In Ace Editor , I want to find text, select a line and replace this text. I can find the text (using my own tags to find them) and it works. I can also get the line (row) number using the following code:
editor.find('needle',{
backwards: true,
wrap: true,
caseSensitive: true,
range: null,
wholeWord: true,
regExp: false
})
editor.$search.set({
needle: /(start_#D1_SavePos)/
});
var found = editor.$search.find(editor.getSession()),
Range = require('ace/range').Range,
mine = new Range(found.start.row+1, found.start.column-1, found.end.row+1, found.end.column),
D1SavePos = (editor.session.getTextRange(mine)),
rowOfD1SavePos = (mine+1),
newD1SavePos = document.getElementById("highestBTTXT").value,
D1SavePos = D1SavePos.replace(/R13=0/, "R13=" + newD1SavePos);
I tried to make a row selection with, because the row number for reading is stored in "rowOfD1SavePos":
editor.selection.moveCursorToPosition(rowOfD1SavePos);
but it does not work. If this works, I want to replace this string with the value "D1SavePos"
UPDATE 10.25.14
This is my perfect working solution:
editor.find('needle',{
backwards: true,
wrap: true,
caseSensitive: true,
range: null,
wholeWord: true,
regExp: false
});
editor.$search.set({ needle: /(start_#D1_SavePos)/ });
var found = editor.$search.find(editor.getSession()),
Range = require('ace/range').Range,
row = new Range(found.start.row+1, found.start.column-1, found.end.row+1, found.end.column),
D1SavePos = (editor.session.getTextRange(row)),
newD1SavePos = document.getElementById("highestBTTXT").value;
D1SavePos = D1SavePos.replace(/R13=0/, "R13=" + newD1SavePos);
editor.selection.moveCursorToPosition({row: row, column: 0});
editor.session.replace(new Range(row, 0, row, Number.MAX_VALUE), D1SavePos);