Skip to content

Commit

Permalink
fix: selection and expanded state not always stored correctly in hist…
Browse files Browse the repository at this point in the history
…ory (#73)
  • Loading branch information
josdejong committed Apr 28, 2022
1 parent 89771a6 commit 702fba1
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 167 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ type RenderValueProps = {
isSelected: boolean
isEditing: boolean
normalization: ValueNormalization
onPatch: (patch: JSONPatchDocument, newSelection: Selection | null) => void
onPatch: (patch: JSONPatchDocument) => void
onPasteJson: (pastedJson: { path: Path; contents: JSON }) => void
onSelect: (selection: Selection) => void
onFind: (findAndReplace: boolean) => void
Expand Down
6 changes: 4 additions & 2 deletions src/lib/components/JSONEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
content = updatedContent
}
export function patch(operations, newSelection) {
export function patch(operations) {
if (content.json === undefined) {
try {
content = {
Expand All @@ -133,7 +133,9 @@
}
if (refTreeMode) {
return refTreeMode.patch(operations, newSelection)
// Note that tree mode has an optional afterPatch callback.
// right now we don's support this in the public API.
return refTreeMode.patch(operations)
}
if (refCodeMode) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/modes/treemode/JSONNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@
})
if (operations) {
context.onPatch(operations, updatedFullSelection || context.getFullSelection())
context.onPatch(operations, () => ({
selection: updatedFullSelection || context.getFullSelection()
}))
} else {
// the user did click inside the selection and no contents have been dragged,
// select the clicked item
Expand Down
Loading

0 comments on commit 702fba1

Please sign in to comment.