Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add updateSelection to JSONEditor #229

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib/components/JSONEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
JSONParser,
JSONPatchResult,
JSONPathParser,
JSONSelection,
OnBlur,
OnChange,
OnChangeMode,
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions src/lib/components/modes/JSONEditorRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
JSONParser,
JSONPatchResult,
JSONPathParser,
JSONSelection,
MenuItem,
MenuSeparatorItem,
OnBlur,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modes/tablemode/TableMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
}
}

function updateSelection(
export function updateSelection(
selection:
| JSONSelection
| undefined
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
let text: string | undefined
let parseError: ParseError | undefined = undefined

function updateSelection(
export function updateSelection(
selection:
| JSONSelection
| undefined
Expand Down