Skip to content

Commit

Permalink
fix: cannot select a key or value when clicking inside the selection
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Apr 5, 2022
1 parent 22c4371 commit 331254a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib/components/modes/treemode/JSONNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import { forEachKey } from '../../../logic/documentState.js'
import { onMoveSelection } from '../../../logic/dragging.js'
import { forEachIndex } from '../../../utils/arrayUtils.js'
import { getDataPathFromTarget } from '../../../utils/domUtils.js'
export let value
export let path
Expand Down Expand Up @@ -267,13 +268,15 @@
}
dragging = {
initialTarget: event.target,
initialClientY: event.clientY,
initialContentTop: findContentTop(),
updatedValue: undefined,
updatedState: undefined,
updatedSelection: undefined,
items,
indexOffset: 0
indexOffset: 0,
didMoveItems: false // whether items have been moved during dragging or not
}
singleton.dragging = true
Expand All @@ -299,7 +302,8 @@
updatedValue,
updatedState,
updatedSelection,
indexOffset
indexOffset,
didMoveItems: true
}
}
}
Expand All @@ -318,6 +322,15 @@
if (operations) {
context.onPatch(operations, updatedFullSelection || context.getFullSelection())
} else {
// the user did click inside the selection and no contents have been dragged,
// select the clicked item
if (event.target === dragging.initialTarget && !dragging.didMoveItems) {
context.onSelect({
type: getSelectionTypeFromTarget(event.target),
path: getDataPathFromTarget(event.target)
})
}
}
dragging = undefined
Expand Down

0 comments on commit 331254a

Please sign in to comment.