From 19d434c366c5fa9112bb8a35281c1197ef904203 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Wed, 23 Jul 2025 17:00:08 +1000 Subject: [PATCH] add default selection tool --- packages/excalidraw/components/App.tsx | 16 ++++++++++++++-- packages/excalidraw/types.ts | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index d3931636dc..e3c0fde4dc 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -458,6 +458,7 @@ import type { GenerateDiagramToCode, NullableGridSize, Offsets, + ActiveTool, } from "../types"; import type { RoughCanvas } from "roughjs/bin/canvas"; import type { Action, ActionResult } from "../actions/types"; @@ -650,9 +651,14 @@ class App extends React.Component { >(); onRemoveEventListenersEmitter = new Emitter<[]>(); + defaultSelectionTool: "selection" | "lasso" = "selection"; + constructor(props: AppProps) { super(props); const defaultAppState = getDefaultAppState(); + this.defaultSelectionTool = this.isMobileOrTablet() + ? ("lasso" as const) + : ("selection" as const); const { excalidrawAPI, viewModeEnabled = false, @@ -2338,6 +2344,7 @@ class App extends React.Component { }; } const scene = restore(initialData, null, null, { repairBindings: true }); + const activeTool = scene.appState.activeTool; scene.appState = { ...scene.appState, theme: this.props.theme || scene.appState.theme, @@ -2347,8 +2354,13 @@ class App extends React.Component { // with a library install link, which should auto-open the library) openSidebar: scene.appState?.openSidebar || this.state.openSidebar, activeTool: - scene.appState.activeTool.type === "image" - ? { ...scene.appState.activeTool, type: "selection" } + activeTool.type === "image" || + activeTool.type === "lasso" || + activeTool.type === "selection" + ? { + ...activeTool, + type: this.defaultSelectionTool, + } : scene.appState.activeTool, isLoading: false, toast: this.state.toast, diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts index a673df1a00..899b20341d 100644 --- a/packages/excalidraw/types.ts +++ b/packages/excalidraw/types.ts @@ -733,6 +733,8 @@ export type AppClassProperties = { onPointerUpEmitter: App["onPointerUpEmitter"]; updateEditorAtom: App["updateEditorAtom"]; + + defaultSelectionTool: "selection" | "lasso"; }; export type PointerDownState = Readonly<{