fix(paper): fix doubleclick
This commit is contained in:
@@ -805,6 +805,68 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
.updateSelectedPath(useBottomToolsStore.getState().activeImage, "ADD")
|
.updateSelectedPath(useBottomToolsStore.getState().activeImage, "ADD")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getPanHitTolerance = (baseTolerance = 8) =>
|
||||||
|
usePaperStore.getState().paperScope
|
||||||
|
? baseTolerance / useTopToolsStore.getState().scale
|
||||||
|
: 0
|
||||||
|
|
||||||
|
const createPanHitOptions = (
|
||||||
|
tolerance: number,
|
||||||
|
match: (hit: paper.HitResult) => boolean
|
||||||
|
) => ({
|
||||||
|
segments: true,
|
||||||
|
stroke: true,
|
||||||
|
curves: true,
|
||||||
|
fill: true,
|
||||||
|
guides: false,
|
||||||
|
tolerance,
|
||||||
|
match,
|
||||||
|
})
|
||||||
|
|
||||||
|
const resolvePanHitResult = (projectPoint: paper.Point) => {
|
||||||
|
const group = usePaperStore.getState().group
|
||||||
|
if (!group) return null
|
||||||
|
|
||||||
|
const supportHit = group.hitTest(
|
||||||
|
projectPoint,
|
||||||
|
createPanHitOptions(getPanHitTolerance(), (hit) =>
|
||||||
|
["pathCircle", "pathBuff"].includes(hit.item.data?.type || "")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if (supportHit) return supportHit
|
||||||
|
|
||||||
|
return group.hitTest(
|
||||||
|
projectPoint,
|
||||||
|
createPanHitOptions(0, (hit) =>
|
||||||
|
["rectangle", "polygon", "brush", "point"].includes(
|
||||||
|
hit.item.data?.type || ""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearCurrentSelection = () => {
|
||||||
|
let shouldClearSupport = false
|
||||||
|
|
||||||
|
usePaperStore
|
||||||
|
.getState()
|
||||||
|
.group!.getItems({
|
||||||
|
data: { selected: true },
|
||||||
|
})
|
||||||
|
.forEach((item) => {
|
||||||
|
if (item.data.selected) {
|
||||||
|
item.data.selected = false
|
||||||
|
shouldClearSupport = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (shouldClearSupport) {
|
||||||
|
usePaperSupportStore.getState().clearAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCancelSelect()
|
||||||
|
}
|
||||||
|
|
||||||
panTool.onMouseDown = (e: { event: MouseEvent; point: paper.Point }) => {
|
panTool.onMouseDown = (e: { event: MouseEvent; point: paper.Point }) => {
|
||||||
if (startMiddleMousePan(e.event)) return
|
if (startMiddleMousePan(e.event)) return
|
||||||
if (pressCtrl) return
|
if (pressCtrl) return
|
||||||
@@ -825,16 +887,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
"local"
|
"local"
|
||||||
)
|
)
|
||||||
|
|
||||||
let hitResult = usePaperStore.getState().group?.hitTest(e.point, {
|
let hitResult = resolvePanHitResult(e.point)
|
||||||
segments: true,
|
|
||||||
stroke: true,
|
|
||||||
curves: true,
|
|
||||||
fill: true,
|
|
||||||
guide: false,
|
|
||||||
tolerance: usePaperStore.getState().paperScope
|
|
||||||
? 8 / useTopToolsStore.getState().scale
|
|
||||||
: 0,
|
|
||||||
})
|
|
||||||
console.log("hitResult", hitResult)
|
console.log("hitResult", hitResult)
|
||||||
let lastTagDataId = -1
|
let lastTagDataId = -1
|
||||||
if (activePath?.data.id) {
|
if (activePath?.data.id) {
|
||||||
@@ -941,35 +994,16 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
|
|
||||||
if (pressShift) {
|
if (pressShift) {
|
||||||
} else {
|
} else {
|
||||||
// not press shift
|
const selectedIds =
|
||||||
let selectedItems = usePaperStore.getState().group!.getItems({
|
useObjectStore.getState().selectedPath[
|
||||||
data: { selected: true },
|
useBottomToolsStore.getState().activeImage
|
||||||
})
|
] || []
|
||||||
if (selectedItems && selectedItems.length) {
|
const hitId = hitResult?.item?.data?.id
|
||||||
selectedItems.forEach((item) => {
|
const keepCurrentSelection =
|
||||||
if (item.data.selected) {
|
hitId && selectedIds.length === 1 && selectedIds[0] === hitId
|
||||||
let itemHitResult = item.hitTest(point, {
|
|
||||||
segments: true,
|
|
||||||
stroke: true,
|
|
||||||
curves: true,
|
|
||||||
fill: true,
|
|
||||||
guide: false,
|
|
||||||
tolerance: usePaperStore.getState().paperScope
|
|
||||||
? 8 / usePaperStore.getState().paperScope!.view.zoom
|
|
||||||
: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!itemHitResult) {
|
if (!keepCurrentSelection) {
|
||||||
item.data.selected = false
|
clearCurrentSelection()
|
||||||
usePaperSupportStore.getState().clearAll()
|
|
||||||
|
|
||||||
handleCancelSelect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// item.data.selected = false;
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
handleCancelSelect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user