简体   繁体   English

如何在Monaco编辑器中监视文件是否从外部更改?

[英]How to monitor if file changed externally in Monaco editor?

Is there an API for listening external file changes in Monaco editor? 摩纳哥编辑器中是否有用于监听外部文件更改的API?

I am developing a react application and my solution is to keep the current modal as a state and use the onDidChangeContent event to compare the current model for any changes. 我正在开发一个onDidChangeContent应用程序,我的解决方案是将当前模式保持为状态,并使用onDidChangeContent事件比较当前模型的任何更改。

Is this a better approach or what could be the best approach for listing external changes to load them to the editor? 这是更好的方法,还是列出外部更改以将其加载到编辑器的最佳方法是什么?

You could check it using setInterval() or setTimeout() functions and AJAX. 您可以使用setInterval()setTimeout()函数和AJAX进行检查。 Each second you can load your file and compare it with the last loaded file content in Monaco editor. 您可以每秒载入文件,并将其与Monaco编辑器中最后载入的文件内容进行比较。 If the file content is not the same then load it again or ask a user before about it. 如果文件内容不同,则再次加载文件或询问用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM