admin管理员组

文章数量:1431391

so I have a textarea surrounded by a DIV container:

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

and this textarea is tranformed into a code editor using CodeMirror:

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. 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?

so I have a textarea surrounded by a DIV container:

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

and this textarea is tranformed into a code editor using CodeMirror:

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. 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?

Share Improve this question edited Jun 15, 2011 at 17:19 gblazex 50.2k12 gold badges99 silver badges92 bronze badges asked Jun 15, 2011 at 17:14 AlexAlex 66.2k185 gold badges460 silver badges651 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

from CodeMirror manual (assuming you're using version 2)

本文标签: javascriptCodeMirror 2wrong editor height after a hidden textarea unhidesStack Overflow