从窗口对象中查找摩纳哥编辑器中光标的位置

问题描述 投票:0回答:1

我试图在已创建的页面上的摩纳哥编辑器的编辑器实例中找到光标位置。我通过浏览器扩展来执行此操作,因此我无法访问创建编辑器的代码。

我只想找到编辑器中光标的位置。但为此我需要以某种方式获取页面上编辑器的实例。

我可以使用模型和编辑器的 DOM 元素的组合来做到这一点吗?

我可以看到

monaco.editor
上有一个
window
属性,但
window.monaco.editor.getEditors()
不是函数。

const model = monaco.editor.getModels()[0]; // Returns the actual model used on the page

const container = document.querySelector(".monaco-editor").parentElement; // the editor in the DOM

const editorInstance = window.monaco.editor.getEditors(); // Not a function
javascript visual-studio-code google-chrome-extension monaco-editor
1个回答
0
投票

如果您有对编辑器容器元素的引用,您可以执行类似 this 的操作来获取相对于编辑器左上角的鼠标位置(或者我不理解您的要求?)

© www.soinside.com 2019 - 2024. All rights reserved.