简体   繁体   English

摩纳哥编辑器显示所有行

[英]Monaco Editor reveal all lines

I'm using Microsoft's Monaco Editor library to create a code editor on a webpage and it's great, but as it seems, for performance reasons, only the visible lines are actually rendered, which does not sound like a problem it actually is when you want to print the contents of the editor.我正在使用Microsoft 的 Monaco Editor库在网页上创建一个代码编辑器,它很棒,但看起来,出于性能原因,实际上只渲染了可见的线条,这听起来不像是你想要的问题打印编辑器的内容。

Is there a way I could force the rendering of all lines?有没有办法强制渲染所有线条?

My best guess was我最好的猜测是

editor.revealRange

and other editor.reveal* methods, but none of that seem to work.和其他editor.reveal*方法,但似乎都不起作用。

The reveal<\/code> methods exist to scroll the editor to a specific position.存在reveal<\/code>方法以将编辑器滚动到特定位置。 Instead you can just get the full content of the model and print that:相反,您可以获取模型的全部内容并打印:

const content = editor.getModel().getValue();

Scroll to the top, run滚动到顶部,运行

HTMLDivElement.prototype.removeChild=function(){}

then scroll to the bottom.然后滚动到底部。 Voilà, all the lines are rendered.瞧,所有的线条都被渲染了。 Some even twice, but that's ok since they're positioned absolute.有些甚至两次,但没关系,因为它们是绝对定位的。

You could try to avoid duplicates via您可以尝试通过避免重复

HTMLDivElement.prototype.reallyRemoveChild=HTMLDivElement.prototype.removeChild;
HTMLDivElement.prototype.removeChild=function(el){
    if(el.parentElement.querySelectorAll(`[style="${el.getAttribute('style')}"]`).length === 2)
    this.reallyRemoveChild.apply(this, arguments)
};

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

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