Ace Editor: Lock or Readonly Code Segment

后端 未结 3 2054
深忆病人
深忆病人 2020-12-30 03:38

Using the Ace Code Editor can I lock or make readonly a segment of code but still allow other lines of code to be written or edited during a session?

3条回答
  •  情书的邮戳
    2020-12-30 03:59

    You can do it easily by listening to the exec events:

    // Prevent editing first and last line of editor
    editor.commands.on("exec", function(e) { 
      var rowCol = editor.selection.getCursor();
      if ((rowCol.row === 0) || ((rowCol.row + 1) === editor.session.getLength())) {
        e.preventDefault();
        e.stopPropagation();
      }
    });
    

    Source: https://jsfiddle.net/tripflex/y0huvc1b/

提交回复
热议问题