Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deselect nodes even if select feature of clicked is disabled #401

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions packages/sprotty/src/features/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ export class SelectMouseListener extends MouseListener {

wasSelected = false;
hasDragged = false;
isMouseDown = false;

override mouseDown(target: SModelElementImpl, event: MouseEvent): (Action | Promise<Action>)[] {
if (event.button !== 0) {
return [];
}
this.isMouseDown = true;
const buttonHandled = this.handleButton(target, event);
if (buttonHandled) {
return buttonHandled;
Expand All @@ -151,18 +153,14 @@ export class SelectMouseListener extends MouseListener {
if (!isCtrlOrCmd(event)) {
deselectedElements = this.collectElementsToDeselect(target, selectableTarget);
}
if (selectableTarget !== undefined) {
if (!selectableTarget.selected) {
this.wasSelected = false;
return this.handleSelectTarget(selectableTarget, deselectedElements, event);
} else if (isCtrlOrCmd(event)) {
this.wasSelected = false;
return this.handleDeselectTarget(selectableTarget, event);
} else {
this.wasSelected = true;
}
if (!selectableTarget.selected) {
this.wasSelected = false;
return this.handleSelectTarget(selectableTarget, deselectedElements, event);
} else if (isCtrlOrCmd(event)) {
this.wasSelected = false;
return this.handleDeselectTarget(selectableTarget, event);
} else {
return this.handleDeselectAll(deselectedElements, event);
this.wasSelected = true;
}
}
return [];
Expand Down Expand Up @@ -217,7 +215,7 @@ export class SelectMouseListener extends MouseListener {
}

override mouseMove(target: SModelElementImpl, event: MouseEvent): Action[] {
this.hasDragged = true;
this.hasDragged = this.isMouseDown;
return [];
}

Expand All @@ -227,14 +225,15 @@ export class SelectMouseListener extends MouseListener {
const selectableTarget = findParentByFeature(target, isSelectable);
if (selectableTarget !== undefined) {
if (this.wasSelected) {
return [SelectAction.create({selectedElementsIDs:[selectableTarget.id],deselectedElementsIDs:[]})];
return [SelectAction.create({ selectedElementsIDs: [selectableTarget.id], deselectedElementsIDs: [] })];
}
} else if (target instanceof SModelRootImpl && !findViewportScrollbar(event)) {
// Mouse up on root but not over ViewPort's scroll bars > deselect all
} else if ((target instanceof SModelRootImpl && !findViewportScrollbar(event)) || !(target instanceof SModelRootImpl)) {
// Mouse up on everything that's not root or root but not over ViewPort's scroll bars > deselect all
return this.handleDeselectAll(this.collectElementsToDeselect(target, undefined), event);
}
}
}
this.isMouseDown = false;
this.hasDragged = false;
return [];
}
Expand Down