simplify conditions
This commit is contained in:
@@ -123,15 +123,12 @@ export function Pane({
|
||||
const onPointerDownCapture = (event: ReactPointerEvent): void => {
|
||||
const { resetSelectedElements, domNode } = store.getState();
|
||||
containerBounds.current = domNode?.getBoundingClientRect();
|
||||
|
||||
if (!containerBounds.current) {
|
||||
return;
|
||||
}
|
||||
if (!containerBounds.current) return;
|
||||
|
||||
const eventTargetIsContainer = event.target === container.current;
|
||||
// if a child element has the 'nokey' class, we don't want to swallow the event and don't start a selection
|
||||
const isNoKeyEvent = !eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
||||
const isSelectionActive = (selectionOnDrag && eventTargetIsContainer) || !selectionOnDrag || selectionKeyPressed;
|
||||
const isSelectionActive = (selectionOnDrag && eventTargetIsContainer) || selectionKeyPressed;
|
||||
|
||||
if (isNoKeyEvent || !isSelecting || !isSelectionActive || event.button !== 0 || !event.isPrimary) {
|
||||
return;
|
||||
@@ -159,7 +156,7 @@ export function Pane({
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!eventTargetIsContainer || paneClickDistance === 0 || !selectionOnDrag) {
|
||||
if (paneClickDistance === 0 || selectionKeyPressed) {
|
||||
resetSelectedElements();
|
||||
|
||||
onSelectionStart?.(event);
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
// We start the selection process when the user clicks down on the pane
|
||||
function onPointerDownCapture(event: PointerEvent) {
|
||||
containerBounds = container?.getBoundingClientRect();
|
||||
if (!containerBounds) return;
|
||||
|
||||
const eventTargetIsContainer = event.target === container;
|
||||
|
||||
@@ -88,15 +89,13 @@
|
||||
!eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
||||
|
||||
const isSelectionActive =
|
||||
(selectionOnDrag && eventTargetIsContainer) || !selectionOnDrag || store.selectionKeyPressed;
|
||||
(selectionOnDrag && eventTargetIsContainer) || store.selectionKeyPressed;
|
||||
|
||||
if (
|
||||
!store.elementsSelectable ||
|
||||
!isSelecting ||
|
||||
event.button !== 0 ||
|
||||
!containerBounds ||
|
||||
isNoKeyEvent ||
|
||||
!isSelecting ||
|
||||
!isSelectionActive ||
|
||||
event.button !== 0 ||
|
||||
!event.isPrimary
|
||||
) {
|
||||
return;
|
||||
@@ -122,7 +121,7 @@
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (paneClickDistance === 0 || !selectionOnDrag) {
|
||||
if (paneClickDistance === 0 || store.selectionKeyPressed) {
|
||||
store.unselectNodesAndEdges();
|
||||
|
||||
onselectionstart?.(event);
|
||||
@@ -219,8 +218,8 @@
|
||||
|
||||
store.selectionRect = null;
|
||||
|
||||
if (selectionInProgress && selectedNodeIds.size > 0) {
|
||||
store.selectionRectMode = 'nodes';
|
||||
if (selectionInProgress) {
|
||||
store.selectionRectMode = selectedNodeIds.size > 0 ? 'nodes' : null;
|
||||
}
|
||||
|
||||
if (selectionInProgress) {
|
||||
|
||||
Reference in New Issue
Block a user