Search code examples
javascriptregexace-editor

Replace content of the line (in ace.editor) and overwrite it


I have some Content in an ace.editor. and now i have an Trigger-Button which puts new text in that actual line - this works, but i want to overwrite the complete content in line (filled with Tabs and numbers) like this:

That line, where the Cursor has his actual possition should be overrited complete and filled with new Content. with my code (see below) i can write in the Editor but it will not overwrite it.

See my code, like i tryed:

function Textuebergabe_NP01(text) {
    null_tabelle_dues1_text.insert(
       null_tabelle_dues1_text.replace(/^.*,\s*RA:\s*/, "") + text + '\r\n    '
    );
}

Solution

  • To replace contents of a line use editor.session.replace function. like this

    var Range = require("ace/range").Range
    var row = editor.selection.lead.row
    var newText = "someText"
    editor.session.replace(new Range(row, 0, row, Number.MAX_VALUE), newText)