How to make multiple chunk of lines readonly in ace editor
<p>I tried to make parts of code read-only in Ace editor. </p>

<p>I have tried by using code given in <a href="http://jsfiddle.net/bzwheeler/btsxgena/" rel="noreferrer">JsFiddle</a></p>

<pre><code>$(function() {
    var editor     = ace.edit("editor1")
        , session  = editor.getSession()
        , Range    = require("ace/range").Range
        , range    = new Range(1, 4, 1, 10)
        , markerId = session.addMarker(range, "readonly-highlight");

    session.setMode("ace/mode/javascript");
    editor.keyBinding.addKeyboardHandler({
        handleKeyboard : function(data, hash, keyString, keyCode, event) {
            if (hash === -1 || (keyCode &lt;= 40 &amp;&amp; keyCode &gt;= 37)) return false;

            if (intersects(range)) {
                return {command:"null", passEvent:false};
            }
        }
    });

    before(editor, 'onPaste', preventReadonly);
    before(editor, 'onCut',   preventReadonly);

    range.start  = session.doc.createAnchor(range.start);
    range.end    = session.doc.createAnchor(range.end);
    range.end.$insertRight = true;

    function before(obj, method, wrapper) {
        var orig = obj[method];
        obj[method] = function() {
            var args = Array.prototype.slice.call(arguments);
            return wrapper.call(this, function(){
                return orig.apply(obj, args);
            }, args);
        }

        return obj[method];
    }

    function intersects(range) {
        return editor.getSelectionRange().intersects(range);
    }

    function preventReadonly(next, args) {
        if (intersects(range)) return;
        next();
    }
});
</code></pre>

<p>I got a problem when I keep pressing backspace it went into the read-only part and there was no editable part left.</p>

<p>How can I make multiple chunks of code read-only and avoid last character from read-only getting deleted.</p>

<p>Also, how to achieve the whole thing dynamically where I have markers in text specifying editable portions ?</p>