Skip to content

Commit

Permalink
Allow clicking feature with a slight drag
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 19, 2025
1 parent 0ebd461 commit 662c77e
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,19 @@ const SvgFeatureRendering = observer(function SvgFeatureRendering(props: {
const [height, setHeight] = useState(maxConfHeight)
const [movedDuringLastMouseDown, setMovedDuringLastMouseDown] =
useState(false)
const [initialMousePos, setInitialMousePos] = useState<{
x: number
y: number
} | null>(null)

const mouseDown = useCallback(
(event: React.MouseEvent) => {
setMouseIsDown(true)
setMovedDuringLastMouseDown(false)
setInitialMousePos({
x: event.clientX,
y: event.clientY,
})
return onMouseDown?.(event)
},
[onMouseDown],
Expand All @@ -259,6 +267,7 @@ const SvgFeatureRendering = observer(function SvgFeatureRendering(props: {
const mouseUp = useCallback(
(event: React.MouseEvent) => {
setMouseIsDown(false)
setInitialMousePos(null)
return onMouseUp?.(event)
},
[onMouseUp],
Expand All @@ -269,8 +278,12 @@ const SvgFeatureRendering = observer(function SvgFeatureRendering(props: {
if (!ref.current) {
return
}
if (mouseIsDown) {
setMovedDuringLastMouseDown(true)
if (mouseIsDown && initialMousePos) {
const dx = event.clientX - initialMousePos.x
const dy = event.clientY - initialMousePos.y
if (Math.abs(dx) > 8 || Math.abs(dy) > 8) {
setMovedDuringLastMouseDown(true)
}
}
const { left, top } = ref.current.getBoundingClientRect()
const offsetX = event.clientX - left
Expand All @@ -289,6 +302,7 @@ const SvgFeatureRendering = observer(function SvgFeatureRendering(props: {
}
},
[
initialMousePos,
blockKey,
bpPerPx,
mouseIsDown,
Expand Down

0 comments on commit 662c77e

Please sign in to comment.