josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
820 stars 108 forks source link

Line numbers are rendered incorrectly #234

Closed EnigmaJJ closed 1 year ago

EnigmaJJ commented 1 year ago

Hi, I used vanilla-jsoneditor in React. I found line numbers are rendered incorrectly when the editor was rendered firstly, and once the editor has the focus, line numbers are rendered correctly. I try to use refresh when I set content, but it doesn't help.

image

josdejong commented 1 year ago

Can it be that your editor is first rendered inside a div with height 0, or a div that is not yet attached to the dom, or with a different font size or so? Best would be to figure out the cause of that and initialize the editor right in one go. Alternatively, you can force the editor to re-render by calling jsoneditor.refresh().

EnigmaJJ commented 1 year ago

Thanks for your reply.

I guess it may be related to the initialization order of components, because sometimes it was rendered as follows: image

The editor was used in the Modal of antd, and I created the editor in the componentDidMount. But like I mentioned, I try to call refresh when I set content, but it doesn't help, it is strange. :(

josdejong commented 1 year ago

Is it possible to to create a minimal example demonstrating the issue?

EnigmaJJ commented 1 year ago

https://codesandbox.io/s/modest-jones-ii99yu I created a demo. If you click Open button, you will see: image

I call refresh in: image am i doing it right? :)

josdejong commented 1 year ago

I see the model you use from Ant Design uses animation when opening the modal, changing the size or zoom level or so from 0 to the actual size in something like 200ms. You have to call .refresh() after the animation has finished. Or alternatively, disable the animation. Ideal would be if the modal has a callback when animation finished but I didn't see that.

EnigmaJJ commented 1 year ago

I understand, thank you for your patient reply :)