diff --git a/src/lib/components/JSONEditor.svelte b/src/lib/components/JSONEditor.svelte index 8c59d966..af827333 100644 --- a/src/lib/components/JSONEditor.svelte +++ b/src/lib/components/JSONEditor.svelte @@ -29,6 +29,7 @@ JSONParser, JSONPatchResult, JSONPathParser, + JSONSelection, OnBlur, OnChange, OnChangeMode, @@ -235,6 +236,13 @@ await refJSONEditorRoot.scrollTo(path) } + export function updateSelection(selection: + | JSONSelection + | undefined + | ((selection: JSONSelection | undefined) => JSONSelection | undefined)): void { + return refJSONEditorRoot.updateSelection(selection) + } + export function findElement(path: JSONPath): Element { return refJSONEditorRoot.findElement(path) } diff --git a/src/lib/components/modes/JSONEditorRoot.svelte b/src/lib/components/modes/JSONEditorRoot.svelte index 9c151978..573539e7 100644 --- a/src/lib/components/modes/JSONEditorRoot.svelte +++ b/src/lib/components/modes/JSONEditorRoot.svelte @@ -5,6 +5,7 @@ JSONParser, JSONPatchResult, JSONPathParser, + JSONSelection, MenuItem, MenuSeparatorItem, OnBlur, @@ -194,6 +195,20 @@ } } + export function updateSelection( + selection: + | JSONSelection + | undefined + | ((selection: JSONSelection | undefined) => JSONSelection | undefined) + ) : void { + if (refTreeMode) { + return refTreeMode.updateSelection(selection) + } else { + // TODO: implement scrollTo for text mode + throw new Error(`Method updateSelection is not available in mode "${mode}"`) + } + } + export function findElement(path: JSONPath): Element | null { if (refTreeMode) { return refTreeMode.findElement(path) diff --git a/src/lib/components/modes/tablemode/TableMode.svelte b/src/lib/components/modes/tablemode/TableMode.svelte index 9d2aa64a..cad5da8c 100644 --- a/src/lib/components/modes/tablemode/TableMode.svelte +++ b/src/lib/components/modes/tablemode/TableMode.svelte @@ -260,7 +260,7 @@ } } - function updateSelection( + export function updateSelection( selection: | JSONSelection | undefined diff --git a/src/lib/components/modes/treemode/TreeMode.svelte b/src/lib/components/modes/treemode/TreeMode.svelte index 6ec1671f..19ed52bd 100644 --- a/src/lib/components/modes/treemode/TreeMode.svelte +++ b/src/lib/components/modes/treemode/TreeMode.svelte @@ -215,7 +215,7 @@ let text: string | undefined let parseError: ParseError | undefined = undefined - function updateSelection( + export function updateSelection( selection: | JSONSelection | undefined