![](/img/trans.png)
[英]Syntax highlighter not working using codemirror 2 with Next.js
[英]Facing issue in using Codemirror . Correct syntax to execute command which is in merge.js
我正在嘗試開發一個在線差異工具。 當前,它正在顯示兩個文件之間的差異。 我還需要上一個差異和下一個差異功能。 根據文檔,可以使用命令“ goNextDiff”和“ goPrevDiff”。 我已經粘貼了相關代碼。 panel1和panel2由ajax調用填充。 我正在獲取內容,並且差異顯示在面板中。 我只想要一次差異,當他單擊下一個差異按鈕時,它應該轉到下一個差異。 我有兩個按鈕試圖執行這些命令。 我不確定它的語法。
</div>
<!-- JS code for the second panel -->
<div id="panel1" style="display:none">
</div>
<!-- the placehorder for the merge/kdiff interface -->
<div id="placeholder"></div>
</body>
<button id = "prevdiff" disabled onclick> Previous Difference </button>
<button id = "nextdiff" disabled> Next Difference </button>
<script type="text/javascript">
dv = CodeMirror.MergeView(document.getElementById("placeholder"), {
value: a1[0],
orig: a2[0],
lineNumbers: true,
mode: "javascript",
highlightDifferences: true
});
var prev = document.getElementById("prevdiff");
var next = document.getElementById("nextdiff");
prev.disabled = false;
next.disabled = false;
prev.onclick = function(){ console.log("prevdiff"); this.execCommand("goPrevDiff"); console.log("prevdiff1");};
next.onclick = function(){ console.log("nextdiff"); this.goNextDiff; console.log("nextdiff1");};
});
</script>
您應該能夠使用CodeMirror對象( 鏈接 )上的execCommand方法執行goNextDiff和goPrevDiff命令。 在您的情況下,CodeMirror實例是變量dv引用的MerveView對象的編輯成員,因此您必須調用:
dv.edit.execCommand("goNextDiff");
dv.edit.execCommand("goPrevDiff");
當然,這只會更改編輯器中的光標位置。 我沒有找到突出顯示特定塊的方法,這就是為什么在我自己的項目( https://easydiff.com )中,我使用了2個獨立的CodeMirror實例以及托管的diff計算和使用我自己的代碼突出顯示塊的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.