mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: on contextMenu, use selected element regardless of z-index (#3668)
This commit is contained in:
parent
60cea7a0c2
commit
c819b653bf
4 changed files with 216 additions and 1 deletions
|
@ -1858,9 +1858,21 @@ class App extends React.Component<AppProps, AppState> {
|
|||
private getElementAtPosition(
|
||||
x: number,
|
||||
y: number,
|
||||
opts?: {
|
||||
/** if true, returns the first selected element (with highest z-index)
|
||||
of all hit elements */
|
||||
preferSelected?: boolean;
|
||||
},
|
||||
): NonDeleted<ExcalidrawElement> | null {
|
||||
const allHitElements = this.getElementsAtPosition(x, y);
|
||||
if (allHitElements.length > 1) {
|
||||
if (opts?.preferSelected) {
|
||||
for (let index = allHitElements.length - 1; index > -1; index--) {
|
||||
if (this.state.selectedElementIds[allHitElements[index].id]) {
|
||||
return allHitElements[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
const elementWithHighestZIndex =
|
||||
allHitElements[allHitElements.length - 1];
|
||||
// If we're hitting element with highest z-index only on its bounding box
|
||||
|
@ -3935,7 +3947,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
event.preventDefault();
|
||||
|
||||
const { x, y } = viewportCoordsToSceneCoords(event, this.state);
|
||||
const element = this.getElementAtPosition(x, y);
|
||||
const element = this.getElementAtPosition(x, y, { preferSelected: true });
|
||||
|
||||
const type = element ? "element" : "canvas";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue