Search code examples
ace-editor

Ace editor set value at current line


I have an issue with the Ace editor. Whenever I insert a value via editor.setValue(val) it gets inserted at the bottom of the document. Is there any way to insert the value at the current line?

Thanks


Solution

  • to insert a line use

    editor.session.insert({row: 1, column: 0}, "text\n")
    

    and to replace a line use

    var Range = require("ace/range").Range // ace.require in no-conflict mode
    editor.session.replace(new Range(1, 0, 1, Number.MAX_VALUE), "text")
    

    or

    editor.session.replace({
        start: {row: 1, column: 0},
        end: {row: 1, column: Number.MAX_VALUE}
    }, "text")