title: ACE EDITOR Find Text, select row and replace text
body: <p>In <a href="https://ace.c9.io/" rel="nofollow noreferrer">Ace Editor</a>, I want to find a text, select row and replace that text. I can find the text (using own tags to find them), and it is working. I'm also able to get the row (line) number by using following code: </p>
  
  <pre><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,
  
      // find tagname "start_#D1_SavePos" in editor 
      mine = new Range(found.start.row+1, found.start.column-1, found.end.row+1, found.end.column),
  
      // read the line number 
      D1SavePos = (editor.session.getTextRange(mine)),
  
      // get next line number, after "start_#D1_SavePos"
      // I need only this and in the editor it will be R13=0
      rowOfD1SavePos = (mine+1),
  
      // Rewrite R13 with value from input text
      // get Value from input field
      newD1SavePos = document.getElementById("highestBTTXT").value, 
  
      //Replace Zero-Value from R13 to new value
      D1SavePos = D1SavePos.replace(/R13=0/, "R13=" + newD1SavePos); 
  
      // Now set this to editors row
  </code></pre>
  
  <p>Tried to make the row selection with, because in "rowOfD1SavePos" the read line number is stored:</p>
  
  <pre><code>    editor.selection.moveCursorToPosition(rowOfD1SavePos);
  </code></pre>
  
  <p>but it is not working. If this works I want to replace this row with the value "D1SavePos"</p>
  
  <p><strong>UPDATE 25.10.14</strong></p>
  
  <p>This is my perfect working solution:</p>
  
  <pre><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,
  
      // Find Coordinates, after Line "start_#D1_SavePos"
      row   = new Range(found.start.row+1, found.start.column-1, found.end.row+1, found.end.column),
  
      // read Text in row
      D1SavePos = (editor.session.getTextRange(row)),
  
      // rewrite
      // get value from input field
      newD1SavePos = document.getElementById("highestBTTXT").value; 
  
  // rewrite R-Parameter with input value
  D1SavePos = D1SavePos.replace(/R13=0/, "R13=" + newD1SavePos); 
  
  // write in editor
  // mark line
  editor.selection.moveCursorToPosition({row: row, column: 0});
  // write    
  editor.session.replace(new Range(row, 0, row, Number.MAX_VALUE), D1SavePos);
  </code></pre>