简体   繁体   English

CodeMirror 2 - 隐藏的textarea取消隐藏后编辑器高度错误

[英]CodeMirror 2 - wrong editor height after a hidden textarea unhides

so I have a textarea surrounded by a DIV container: 所以我有一个被DIV容器包围的textarea:

<div>
  <textarea id="code"> some text here </textarea>
</div>

and this textarea is tranformed into a code editor using CodeMirror: 并使用CodeMirror将此textarea转换为代码编辑器:

CodeMirror.fromTextArea('code', {
  lineNumbers: true,
  matchBrackets: true,
  mode: 'text/html'
});

the problem is that when the container of the textarea is hidden (some times it is, depending on what the user chooses to display), then after toggling to unhide it the CodeMirror editor doesn't appear like it should. 问题是,当textarea的容器被隐藏时(有时它取决于用户选择显示的内容),然后在切换取消隐藏后,CodeMirror编辑器看起来不应该如此。 It only shows one line, and you have to actually click inside it to redraw and show properly. 它只显示一行,你必须实际点击它内部才能重绘并正确显示。

Does anyone know a fix for this? 有谁知道解决这个问题?

refresh() 刷新()
If your code does something to change the size of the editor element (window resizes are already listened for), or unhides it, you should probably follow up by calling this method to ensure CodeMirror is still looking as intended. 如果您的代码确实需要更改编辑器元素的大小(已经监听了窗口调整大小),或者取消隐藏它,那么您应该通过调用此方法来跟进,以确保CodeMirror仍然按预期进行查找。

from CodeMirror manual (assuming you're using version 2) 来自CodeMirror手册 (假设您使用的是版本2)

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

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