[英]Get/Restore Monaco editor Undo&Redo stack
我想創建一個系統來存儲Monaco編輯器的Undo&Redo stack
。
為什么? :我有一個Monaco實例,我做了幾處修改。 然后我必須處理該實例並打開一個新實例。 在這里,我想恢復與前一個實例中相同的堆棧狀態。
問題 :如何獲取和恢復Undo&Redo stack
?
更新:當我處理Monaco編輯器實例時,JavaScript環境可以完全銷毀。 它集成在一個能夠與JS
通信的C#
環境中。 我的目標是將Monaco Editor model
存儲在C#
或序列化它。
這一切都與模型有關。
如果您恢復相同的模型,您將擁有撤消和重做堆棧
見例子
var model = editorInstance.getModel();
var viewState = editorInstance.saveViewState();
//Destroy your instance for whatever reason
editorInstance.dispose();
//When you create the new instance load the model that you saved
var newInstance = monaco.editor.create(elem, options);
newInstance.setModel(model);
newInstance.restoreViewState(viewState);
可能有幫助的東西就是與摩納哥事件掛鈎
monaco.editor.onWillDisposeModel(saveModel)
viewState
可用於恢復編輯器的光標位置。
這是非官方的方式:
const {past, future} = editor.getModel()._commandManager;
在您的情況下,您可以在past
和future
運行JSON.stringify
。 然后,當您重新創建編輯器時,您就可以了
const cm = editor.getModel()._commandManager;
cm.past = JSON.parse(past);
cm.future = JSON.parse(future);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.