codemirror / codemirror5

In-browser code editor (version 5, legacy)
http://codemirror.net/5/
MIT License
26.82k stars 4.97k forks source link

CodeMirror editor Code Display Goes Wrong After Setting Document Content #6522

Open HTGAzureX1212 opened 3 years ago

HTGAzureX1212 commented 3 years ago

I am using CodeMirror version 5.58.3, alongside with Vue 3.0.4. Before upgrading to Vue 3, nothing wrong happened when I set the document content of codemirror. But after upgrading to Vue 3, this happened:

image

As you can see in the picture, the cursor is in the absolutely wrong position.

However, this issue does not exist when the content I am setting the document to is empty: image

I am using Google Chrome.

marijnh commented 3 years ago

This sounds like the editor is initialized without being part of the document yet, or while its parent element is hidden. That will cause it to fail to measure its text geometry correctly. You either have to arrange for refresh() to be called when the editor becomes visible, or enable the autorefresh addon.

HTGAzureX1212 commented 3 years ago

"autorefresh"...?

HTGAzureX1212 commented 3 years ago

How do I enable it

HTGAzureX1212 commented 3 years ago

Hmm that doesn't seem to fix it

HTGAzureX1212 commented 3 years ago

Let me try manually calling refresh()

HTGAzureX1212 commented 3 years ago

image Wait, I already refreshed it

HTGAzureX1212 commented 3 years ago

So now the situation is refreshing doesn't work

marijnh commented 3 years ago

Then I'm out of ideas, except to ensure that the editor really is visible, and has its final geometry (i.e. no further CSS or font loading changes it afterwards) when the refresh call is made.

HTGAzureX1212 commented 3 years ago

But umm... the editor is in a tab in which when the component is loaded, it is not visible yet. Only when the user switch to the tab with the editor, the editor then comes visible.

marijnh commented 3 years ago

Well, there's your problem.

HTGAzureX1212 commented 3 years ago

How should I correct it?

HTGAzureX1212 commented 3 years ago

I have this: image

In which the GuildConfigurationSubComponent is the component holding the editor. It is only visible when the activeTab is 2, which, by default, when the tabs are loaded, is 1.

marijnh commented 3 years ago

I don't know Vue, so I can't help you there.

HTGAzureX1212 commented 3 years ago

Ahhh