src/LiveDevelopment/Agents/DOMAgent.js
function applyChange(from, to, text) {
        var delta = from - to + text.length;
        var node = nodeAtLocation(from);

        // insert a text node
        if (!node) {
            if (!(/^\s*$/).test(text)) {
                console.warn("Inserting nodes not supported.");
                node = nodeBeforeLocation(from);
            }
        } else if (node.type === 3) {
            // update a text node
            var value = node.value.substr(0, from - node.location);
            value += text;
            value += node.value.substr(to - node.location);
            node.value = value;
            if (!EditAgent.isEditing) {
                // only update the DOM if the change was not caused by the edit agent
                Inspector.DOM.setNodeValue(node.nodeId, node.value);
            }
        } else {
            console.warn("Changing non-text nodes not supported.");
        }

        // adjust the location of all nodes after the change
        if (node) {
            node.length += delta;
            exports.root.each(function each(n) {
                if (n.location > node.location) {
                    n.location += delta;
                }
                if (n.closeLocation !== undefined && n.closeLocation > node.location) {
                    n.closeLocation += delta;
                }
            });
        }
    }
function applyChange(from, to, text) {
        var delta = from - to + text.length;
        var node = nodeAtLocation(from);

        // insert a text node
        if (!node) {
            if (!(/^\s*$/).test(text)) {
                console.warn("Inserting nodes not supported.");
                node = nodeBeforeLocation(from);
            }
        } else if (node.type === 3) {
            // update a text node
            var value = node.value.substr(0, from - node.location);
            value += text;
            value += node.value.substr(to - node.location);
            node.value = value;
            if (!EditAgent.isEditing) {
                // only update the DOM if the change was not caused by the edit agent
                Inspector.DOM.setNodeValue(node.nodeId, node.value);
            }
        } else {
            console.warn("Changing non-text nodes not supported.");
        }

        // adjust the location of all nodes after the change
        if (node) {
            node.length += delta;
            exports.root.each(function each(n) {
                if (n.location > node.location) {
                    n.location += delta;
                }
                if (n.closeLocation !== undefined && n.closeLocation > node.location) {
                    n.closeLocation += delta;
                }
            });
        }
    }
function applyChange ( from , to , text ) { var delta = from - to + text . length ; var node = nodeAtLocation ( from ) ; // insert a text node if ( ! node ) { if ( ! ( / ^\s*$ / ) . test ( text ) ) { console . warn ( "Inserting nodes not supported." ) ; node = nodeBeforeLocation ( from ) ; } } else if ( node . type === 3 ) { // update a text node var value = node . value . substr ( 0 , from - node . location ) ; value += text ; value += node . value . substr ( to - node . location ) ; node . value = value ; if ( ! EditAgent . isEditing ) { // only update the DOM if the change was not caused by the edit agent Inspector . DOM . setNodeValue ( node . nodeId , node . value ) ; } } else { console . warn ( "Changing non-text nodes not supported." ) ; } // adjust the location of all nodes after the change if ( node ) { node . length += delta ; exports . root . each ( function each ( n ) { if ( n . location > node . location ) { n . location += delta ; } if ( n . closeLocation !== undefined && n . closeLocation > node . location ) { n . closeLocation += delta ; } } ) ; } }
Apply a change
@param {integer} start offset of the change
@param {integer} end offset of the change
@param {string} change text
Apply a change