Skip to content

Commit

Permalink
Don't select elements that are too far away
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Mar 27, 2024
1 parent 8224741 commit 05af43d
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
*/
import { unlock } from '../lock-unlock';

const DISTANCE_THRESHOLD = 500;

function clamp( value, min, max ) {
return Math.min( Math.max( value, min ), max );
}
Expand Down Expand Up @@ -62,7 +64,10 @@ export default function useSelectNearestEditableBlock( {
}
const rect = block.getBoundingClientRect();
const distance = distanceFromRect( x, y, rect );
if ( distance < nearestDistance ) {
if (
distance < nearestDistance &&
distance < DISTANCE_THRESHOLD
) {
nearestDistance = distance;
nearestClientId = clientId;
}
Expand Down

0 comments on commit 05af43d

Please sign in to comment.