mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
shift for additive selection
This commit is contained in:
parent
93cf57b862
commit
7e737f233c
2 changed files with 33 additions and 5 deletions
|
@ -6562,6 +6562,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.lassoTrail.startPath(
|
this.lassoTrail.startPath(
|
||||||
pointerDownState.origin.x,
|
pointerDownState.origin.x,
|
||||||
pointerDownState.origin.y,
|
pointerDownState.origin.y,
|
||||||
|
event.shiftKey,
|
||||||
);
|
);
|
||||||
} else if (this.state.activeTool.type === "text") {
|
} else if (this.state.activeTool.type === "text") {
|
||||||
this.handleTextOnPointerDown(event, pointerDownState);
|
this.handleTextOnPointerDown(event, pointerDownState);
|
||||||
|
@ -7020,7 +7021,10 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearSelectionIfNotUsingSelection = (): void => {
|
private clearSelectionIfNotUsingSelection = (): void => {
|
||||||
if (this.state.activeTool.type !== "selection") {
|
if (
|
||||||
|
this.state.activeTool.type !== "selection" &&
|
||||||
|
this.state.activeTool.type !== "lasso"
|
||||||
|
) {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedElementIds: makeNextSelectedElementIds({}, this.state),
|
selectedElementIds: makeNextSelectedElementIds({}, this.state),
|
||||||
selectedGroupIds: {},
|
selectedGroupIds: {},
|
||||||
|
@ -8261,7 +8265,8 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
selectedElements.length > 0 &&
|
selectedElements.length > 0 &&
|
||||||
!pointerDownState.withCmdOrCtrl &&
|
!pointerDownState.withCmdOrCtrl &&
|
||||||
!this.state.editingTextElement &&
|
!this.state.editingTextElement &&
|
||||||
this.state.activeEmbeddable?.state !== "active"
|
this.state.activeEmbeddable?.state !== "active" &&
|
||||||
|
this.state.activeTool.type !== "lasso"
|
||||||
) {
|
) {
|
||||||
const dragOffset = {
|
const dragOffset = {
|
||||||
x: pointerCoords.x - pointerDownState.origin.x,
|
x: pointerCoords.x - pointerDownState.origin.x,
|
||||||
|
@ -8611,7 +8616,11 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.lassoTrail.endPath();
|
this.lassoTrail.endPath();
|
||||||
selectionSwitch = false;
|
selectionSwitch = false;
|
||||||
} else {
|
} else {
|
||||||
this.lassoTrail.addPointToPath(pointerCoords.x, pointerCoords.y);
|
this.lassoTrail.addPointToPath(
|
||||||
|
pointerCoords.x,
|
||||||
|
pointerCoords.y,
|
||||||
|
event.shiftKey,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// It is very important to read this.state within each move event,
|
// It is very important to read this.state within each move event,
|
||||||
|
|
|
@ -26,6 +26,7 @@ export class LassoTrail extends AnimatedTrail {
|
||||||
private worker: Worker | null = null;
|
private worker: Worker | null = null;
|
||||||
private elementsSegments: Map<string, LineSegment<GlobalPoint>[]> | null =
|
private elementsSegments: Map<string, LineSegment<GlobalPoint>[]> | null =
|
||||||
null;
|
null;
|
||||||
|
private keepPreviousSelection: boolean = false;
|
||||||
|
|
||||||
constructor(animationFrameHandler: AnimationFrameHandler, app: App) {
|
constructor(animationFrameHandler: AnimationFrameHandler, app: App) {
|
||||||
super(animationFrameHandler, app, {
|
super(animationFrameHandler, app, {
|
||||||
|
@ -49,7 +50,7 @@ export class LassoTrail extends AnimatedTrail {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
startPath(x: number, y: number) {
|
startPath(x: number, y: number, keepPreviousSelection = false) {
|
||||||
// clear any existing trails just in case
|
// clear any existing trails just in case
|
||||||
this.endPath();
|
this.endPath();
|
||||||
|
|
||||||
|
@ -57,6 +58,16 @@ export class LassoTrail extends AnimatedTrail {
|
||||||
this.intersectedElements.clear();
|
this.intersectedElements.clear();
|
||||||
this.enclosedElements.clear();
|
this.enclosedElements.clear();
|
||||||
|
|
||||||
|
this.keepPreviousSelection = keepPreviousSelection;
|
||||||
|
|
||||||
|
if (!this.keepPreviousSelection) {
|
||||||
|
this.app.setState({
|
||||||
|
selectedElementIds: {},
|
||||||
|
selectedGroupIds: {},
|
||||||
|
selectedLinearElement: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.worker = new LassoWorker();
|
this.worker = new LassoWorker();
|
||||||
|
|
||||||
|
@ -80,6 +91,12 @@ export class LassoTrail extends AnimatedTrail {
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<ExcalidrawElement["id"], true>);
|
}, {} as Record<ExcalidrawElement["id"], true>);
|
||||||
|
|
||||||
|
if (this.keepPreviousSelection) {
|
||||||
|
for (const id of Object.keys(prevState.selectedElementIds)) {
|
||||||
|
nextSelectedElementIds[id] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const [id] of Object.entries(nextSelectedElementIds)) {
|
for (const [id] of Object.entries(nextSelectedElementIds)) {
|
||||||
const element = this.app.scene.getNonDeletedElement(id);
|
const element = this.app.scene.getNonDeletedElement(id);
|
||||||
if (element && isFrameLikeElement(element)) {
|
if (element && isFrameLikeElement(element)) {
|
||||||
|
@ -123,9 +140,11 @@ export class LassoTrail extends AnimatedTrail {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
addPointToPath = (x: number, y: number) => {
|
addPointToPath = (x: number, y: number, keepPreviousSelection = false) => {
|
||||||
super.addPointToPath(x, y);
|
super.addPointToPath(x, y);
|
||||||
|
|
||||||
|
this.keepPreviousSelection = keepPreviousSelection;
|
||||||
|
|
||||||
this.app.setState({
|
this.app.setState({
|
||||||
lassoSelection: {
|
lassoSelection: {
|
||||||
points:
|
points:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue