jsoneditor icon indicating copy to clipboard operation
jsoneditor copied to clipboard

How to keep position when switching between "tree" and "code" modes?

Open tormozit opened this issue 5 years ago • 3 comments

I have read https://github.com/josdejong/jsoneditor/pull/504 and still find no way to keep position when switching between "tree" and "code" modes. Is there any simple way? And why there is no button to switch between modes?

tormozit avatar Jan 02 '21 06:01 tormozit

I guess you mean #524 instead of #504?

Maybe you can simply create two editors, one in code mode and one in tree mode, and always hide one of the two depending on the actual mode.

josdejong avatar Jan 02 '21 16:01 josdejong

No. I mean if I caret it positioned at row 3 and column 7 in code mode and I switch to tree mode by calling setMode("tree") then caret is moved to row 1 and column 1. But I expected it will be located in that node in which caret was in previous mode.

tormozit avatar Jan 02 '21 19:01 tormozit

Ok I think I understand what you mean. The code mode and tree mode are simply two different editors, they are not aware of each other. When switching to an other mode, there is basically a new editor created which starts with a clean slate. There are currently no methods to somehow keep focus on the node where the caret was.

josdejong avatar Jan 02 '21 21:01 josdejong