如何使Monaco差异编辑器的左侧(原始代码)可编辑?

时间:2019-06-30 22:16:05

标签: diff monaco-editor

我正在寻找一种在Monaco差异编辑器中编辑左右两侧代码的可能性。

我已经尝试过了:

var originalModel = monaco.editor.createModel("heLLo world!", "text/plain");
var modifiedModel = monaco.editor.createModel("hello orlando!", "text/plain");

var diffEditor = monaco.editor.createDiffEditor(
  document.getElementById("container"), 
  { readOnly: false }
);

diffEditor.setModel({
    original: originalModel,
    modified: modifiedModel
});

但是,该(只读)选项仅作用于右侧,默认情况下是可编辑的。

这是一个演示链接: creating-the-diffeditor-hello-diff-world

1 个答案:

答案 0 :(得分:0)

IDiffEditorOptions中设置originalEditable: true

var originalModel = monaco.editor.createModel("heLLo world!", "text/plain");
var modifiedModel = monaco.editor.createModel("hello orlando!", "text/plain");

var diffEditor = monaco.editor.createDiffEditor(document.getElementById("container"), {
    originalEditable: true, // for left pane
    readOnly: true,         // for right pane
});
diffEditor.setModel({
    original: originalModel,
    modified: modifiedModel
});