don't allow dragging hidden points

This commit is contained in:
Aakansha Doshi 2022-09-01 17:30:31 +05:30
parent 8971d06655
commit cd195374bc
2 changed files with 18 additions and 7 deletions

View File

@ -3084,7 +3084,7 @@ class App extends React.Component<AppProps, AppState> {
])
) {
hoverPointIndex = LinearElementEditor.getPointIndexUnderCursor(
element,
this.state.selectedLinearElement,
this.state.zoom,
scenePointerX,
scenePointerY,

View File

@ -380,7 +380,7 @@ export class LinearElementEditor {
return false;
}
const clickedPointIndex = LinearElementEditor.getPointIndexUnderCursor(
element,
appState.selectedLinearElement,
appState.zoom,
scenePointer.x,
scenePointer.y,
@ -566,7 +566,7 @@ export class LinearElementEditor {
}
const clickedPointIndex = LinearElementEditor.getPointIndexUnderCursor(
element,
appState.selectedLinearElement,
appState.zoom,
scenePointer.x,
scenePointer.y,
@ -773,19 +773,30 @@ export class LinearElementEditor {
}
static getPointIndexUnderCursor(
element: NonDeleted<ExcalidrawLinearElement>,
linearElementEditor: LinearElementEditor | null,
zoom: AppState["zoom"],
x: number,
y: number,
) {
if (!linearElementEditor) {
return -1;
}
const element = LinearElementEditor.getElement(
linearElementEditor.elementId,
);
if (!element) {
return -1;
}
const pointHandles =
LinearElementEditor.getPointsGlobalCoordinates(element);
let idx = pointHandles.length;
let idx = linearElementEditor.visiblePointIndexes.length;
// loop from right to left because points on the right are rendered over
// points on the left, thus should take precedence when clicking, if they
// overlap
while (--idx > -1) {
const point = pointHandles[idx];
while (--idx > 0) {
const point = pointHandles[linearElementEditor.visiblePointIndexes[idx]];
if (
distance2d(x, y, point[0], point[1]) * zoom.value <
// +1px to account for outline stroke