Search code examples
javascriptangularjsnode.jsace-editor

what is the return value of getsession.insert in ace editor?


The documentation for ace editor is not very clear on what the return value is for these two functions in editsession: addmarker insert

edit session api ref

the addmarker is not actually adding a marker for me, and the insert is not inserting any lines in the editor. Which is why i thought i should inspect the return values.

Can anyone tell me what the return values are supposed to contain in each case? For insert, i dont get any return value. For addmarker, i get a row number and a column number. For example, row number 2 and column number 550. What is the meaning of this? What information are the return values giving me?

I am storing the edit session in a scope variable(I'm using angularjs) So my commands look something like this:

        var addmarker_ret_value = $scope.aceSession3.addMarker(
            new range(row_1, 0, row_2, 0), "ace_active-line", "fullLine"
        );
var position = {};
position['row'] = row_val;
position['col'] = col_val;
var ret_value = $scope.aceSession3.insert(position,line_content);

Thanks.


Solution

  • addMarker returns markerId which can be used to remove marker later,
    insert returns the position of the end of inserted text

    here's a simple example that inserts string "text" at row 1 column 0, and highlights inserted text for one second.

    position = {row : 1, column: 0}
    endPosition = session.insert(position, "text")
    var Range = require("ace/range").Range
    markerId = session.addMarker(
        Range.fromPoints(position, endPosition), "ace_highlight-marker"
    )
    setTimeout(function() {
       session.removeMarker(markerId)
    }, 1000)