keep alt toggled lasso selection if shift pressed

This commit is contained in:
Ryan Di 2025-03-24 11:10:49 +11:00
parent ff9d32a3fc
commit 5ab8caa6b5

View file

@ -557,7 +557,6 @@ let IS_PLAIN_PASTE_TIMER = 0;
let PLAIN_PASTE_TOAST_SHOWN = false; let PLAIN_PASTE_TOAST_SHOWN = false;
let lastPointerUp: (() => void) | null = null; let lastPointerUp: (() => void) | null = null;
let selectionSwitch = false;
const gesture: Gesture = { const gesture: Gesture = {
pointers: new Map(), pointers: new Map(),
lastCenter: null, lastCenter: null,
@ -4697,6 +4696,7 @@ class App extends React.Component<AppProps, AppState> {
) )
| { type: "custom"; customType: string } | { type: "custom"; customType: string }
) & { locked?: boolean; fromSelection?: boolean }, ) & { locked?: boolean; fromSelection?: boolean },
keepSelection = false,
) => { ) => {
if (!this.isToolSupported(tool.type)) { if (!this.isToolSupported(tool.type)) {
console.warn( console.warn(
@ -4738,7 +4738,21 @@ class App extends React.Component<AppProps, AppState> {
this.store.shouldCaptureIncrement(); this.store.shouldCaptureIncrement();
} }
if (nextActiveTool.type !== "selection") { if (nextActiveTool.type === "lasso") {
return {
...prevState,
activeTool: nextActiveTool,
...(keepSelection
? {}
: {
selectedElementIds: makeNextSelectedElementIds({}, prevState),
selectedGroupIds: makeNextSelectedElementIds({}, prevState),
editingGroupId: null,
multiElement: null,
}),
...commonResets,
};
} else if (nextActiveTool.type !== "selection") {
return { return {
...prevState, ...prevState,
activeTool: nextActiveTool, activeTool: nextActiveTool,
@ -7041,7 +7055,7 @@ class App extends React.Component<AppProps, AppState> {
event: React.PointerEvent<HTMLElement>, event: React.PointerEvent<HTMLElement>,
pointerDownState: PointerDownState, pointerDownState: PointerDownState,
): boolean => { ): boolean => {
if (this.state.activeTool.type === "selection") { if (this.state.activeTool.type === "selection" && !event.altKey) {
const elements = this.scene.getNonDeletedElements(); const elements = this.scene.getNonDeletedElements();
const elementsMap = this.scene.getNonDeletedElementsMap(); const elementsMap = this.scene.getNonDeletedElementsMap();
const selectedElements = this.scene.getSelectedElements(this.state); const selectedElements = this.scene.getSelectedElements(this.state);
@ -8597,24 +8611,29 @@ class App extends React.Component<AppProps, AppState> {
pointerDownState.lastCoords.x = pointerCoords.x; pointerDownState.lastCoords.x = pointerCoords.x;
pointerDownState.lastCoords.y = pointerCoords.y; pointerDownState.lastCoords.y = pointerCoords.y;
if (event.altKey) { if (event.altKey) {
this.setActiveTool({ type: "lasso", fromSelection: true }); this.setActiveTool(
this.lassoTrail.startPath(pointerCoords.x, pointerCoords.y); { type: "lasso", fromSelection: true },
event.shiftKey,
);
this.lassoTrail.startPath(
pointerCoords.x,
pointerCoords.y,
event.shiftKey,
);
this.setAppState({ this.setAppState({
selectionElement: null, selectionElement: null,
}); });
selectionSwitch = true;
} else { } else {
this.maybeDragNewGenericElement(pointerDownState, event); this.maybeDragNewGenericElement(pointerDownState, event);
} }
} else if (this.state.activeTool.type === "lasso") { } else if (this.state.activeTool.type === "lasso") {
if (!event.altKey && selectionSwitch) { if (!event.altKey && this.state.activeTool.fromSelection) {
this.setActiveTool({ type: "selection" }); this.setActiveTool({ type: "selection" });
this.createGenericElementOnPointerDown("selection", pointerDownState); this.createGenericElementOnPointerDown("selection", pointerDownState);
pointerDownState.lastCoords.x = pointerCoords.x; pointerDownState.lastCoords.x = pointerCoords.x;
pointerDownState.lastCoords.y = pointerCoords.y; pointerDownState.lastCoords.y = pointerCoords.y;
this.maybeDragNewGenericElement(pointerDownState, event); this.maybeDragNewGenericElement(pointerDownState, event);
this.lassoTrail.endPath(); this.lassoTrail.endPath();
selectionSwitch = false;
} else { } else {
this.lassoTrail.addPointToPath( this.lassoTrail.addPointToPath(
pointerCoords.x, pointerCoords.x,
@ -8878,7 +8897,6 @@ class App extends React.Component<AppProps, AppState> {
// just in case, tool changes mid drag, always clean up // just in case, tool changes mid drag, always clean up
this.lassoTrail.endPath(); this.lassoTrail.endPath();
selectionSwitch = false;
this.lastPointerMoveCoords = null; this.lastPointerMoveCoords = null;
SnapCache.setReferenceSnapPoints(null); SnapCache.setReferenceSnapPoints(null);