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

How to change the selected node programmatically #227

Closed sagIoTPower closed 1 year ago

sagIoTPower commented 1 year ago

Could you provide a sample how to set the selection to a specific path? I don't see a way/method to change the selected node programmatically.

sagIoTPower commented 1 year ago

Hi,

I explored how this could be achieved and ran a local test. First I exported export function updateSelection(selection: ....) much like export function scrollTo(path: Path) in the following svelte scripts:

src/lib/components/modes/tablemode/TableMode.svelte
src/lib/components/modes/treemode/TreeMode.svelte

Other files I had to touch were:

src/lib/components/modes/JSONEditorRoot.svelte
src/lib/components/JSONEditor.svelte

Finally I could set the selection.

Would it be possible to expose in JSONEditor? function updateSelection(selection: ....)

Thanks

sagIoTPower commented 1 year ago

229 proposed by pull request.

josdejong commented 1 year ago

Thanks @sagIoTPower for your PR!

This will address #163. Do you have any thoughts on the open discussion there, in https://github.com/josdejong/svelte-jsoneditor/issues/163#issuecomment-1277397051?

josdejong commented 1 year ago

I'll close this issue now in favor of #163 to keep the discussion focused.