keep lasso if selected from toolbar

This commit is contained in:
Ryan Di 2025-03-20 20:30:33 +11:00
parent ded26bea97
commit df988e83f6
5 changed files with 15 additions and 4 deletions

View file

@ -532,6 +532,7 @@ export const actionToggleLassoTool = register({
if (appState.activeTool.type !== "lasso") {
activeTool = updateActiveTool(appState, {
type: "lasso",
fromSelection: false,
});
setCursor(app.interactiveCanvas, CURSOR_TYPE.CROSSHAIR);
} else {

View file

@ -52,6 +52,7 @@ export const getDefaultAppState = (): Omit<
type: "selection",
customType: null,
locked: DEFAULT_ELEMENT_PROPS.locked,
fromSelection: false,
lastActiveTool: null,
},
penMode: false,

View file

@ -4696,7 +4696,7 @@ class App extends React.Component<AppProps, AppState> {
}
)
| { type: "custom"; customType: string }
) & { locked?: boolean },
) & { locked?: boolean; fromSelection?: boolean },
) => {
if (!this.isToolSupported(tool.type)) {
console.warn(
@ -8592,7 +8592,7 @@ class App extends React.Component<AppProps, AppState> {
pointerDownState.lastCoords.x = pointerCoords.x;
pointerDownState.lastCoords.y = pointerCoords.y;
if (event.altKey) {
this.setActiveTool({ type: "lasso" });
this.setActiveTool({ type: "lasso", fromSelection: true });
this.lassoTrail.startPath(pointerCoords.x, pointerCoords.y);
this.setAppState({
selectionElement: null,
@ -9684,7 +9684,13 @@ class App extends React.Component<AppProps, AppState> {
return;
}
if (!activeTool.locked && activeTool.type !== "freedraw") {
if (
!activeTool.locked &&
activeTool.type !== "freedraw" &&
// if lasso is turned on but from selection => reset to selection
activeTool.type === "lasso" &&
activeTool.fromSelection
) {
resetCursor(this.interactiveCanvas);
this.setState({
newElement: null,

View file

@ -300,6 +300,8 @@ export interface AppState {
*/
lastActiveTool: ActiveTool | null;
locked: boolean;
// indicates if the current tool is temporarily switched on from the selection tool
fromSelection: boolean;
} & ActiveTool;
penMode: boolean;
penDetected: boolean;

View file

@ -382,7 +382,7 @@ export const updateActiveTool = (
type: ToolType;
}
| { type: "custom"; customType: string }
) & { locked?: boolean }) & {
) & { locked?: boolean; fromSelection?: boolean }) & {
lastActiveToolBeforeEraser?: ActiveTool | null;
},
): AppState["activeTool"] => {
@ -404,6 +404,7 @@ export const updateActiveTool = (
type: data.type,
customType: null,
locked: data.locked ?? appState.activeTool.locked,
fromSelection: data.fromSelection ?? false,
};
};