static/src/apply.js
/**
 * Apply an operation to the Ace Editor.
 * @param {Array} op - the operation to be applied
 * @param {Editor} editor_ - the ace editor to apply the operation on
 */
Apply an operation to the Ace Editor.
@param {Array} op - the operation to be applied
@param {Editor} editor_ - the ace editor to apply the operation on
Apply an operation to the Ace Editor . @param { Array } op - the operation to be applied @param { Editor } editor_ - the ace editor to apply the operation on
function apply(op, editor_){
    if (op[0] == 'ID'){return;}
    const pos = {'row': op[1][0], 'column': op[1][1]};
    if (op[0] == 'INS'){
        editor_.session.insert(pos, op[2]);
    }else if (op[0] == 'DEL'){
        if (pos['column'] == -1){
            const range = {
                'start': {'row': pos['row'] - 1, 'column': editor_.session.getLine(pos['row'] - 1).length},
                'end': {'row': pos['row'], 'column': 0}
            }
            console.log(range);
            editor_.session.remove(range);
        }else{
            const range = {
                'start': {'row': pos['row'], 'column': pos['column']},
                'end': {'row': pos['row'], 'column': pos['column'] + 1}
            }
            editor_.session.remove(range);
        }
    }
}
function apply ( op , editor_ ) { if ( op [ 0 ] == 'ID' ) { return ; } const pos = { 'row' : op [ 1 ] [ 0 ] , 'column' : op [ 1 ] [ 1 ] } ; if ( op [ 0 ] == 'INS' ) { editor_ . session . insert ( pos , op [ 2 ] ) ; } else if ( op [ 0 ] == 'DEL' ) { if ( pos [ 'column' ] == - 1 ) { const range = { 'start' : { 'row' : pos [ 'row' ] - 1 , 'column' : editor_ . session . getLine ( pos [ 'row' ] - 1 ) . length } , 'end' : { 'row' : pos [ 'row' ] , 'column' : 0 } } console . log ( range ) ; editor_ . session . remove ( range ) ; } else { const range = { 'start' : { 'row' : pos [ 'row' ] , 'column' : pos [ 'column' ] } , 'end' : { 'row' : pos [ 'row' ] , 'column' : pos [ 'column' ] + 1 } } editor_ . session . remove ( range ) ; } } }
Apply an operation to the Ace Editor.
Apply an operation to the Ace Editor .
// Default row 0 for now // const range = new ace.require('ace/range').Range(0, op[1], 0, op[1] + 1); // console.log(range);