Skip to content

Commit

Permalink
Add fix on mouse button and text node selection
Browse files Browse the repository at this point in the history
Signed-off-by: massimo.ferraro <[email protected]>
  • Loading branch information
massimo-ferraro authored and flo-dup committed Nov 4, 2024
1 parent 13f3bca commit e10b9e3
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,25 @@ export class NetworkAreaDiagramViewer {
}

private handleStartDragSelectEvent(event: Event) {
// check mouse button
if ((event as MouseEvent).button !== 0) {
return;
}
// check element is draggable or selectable
const draggableElem = DiagramUtils.getDraggableFrom(event.target as SVGElement);
if (!draggableElem) {
return;
}
this.shiftKeyOnMouseDown = !!(event as MouseEvent).shiftKey;
// avoid selecting text nodes
if (this.shiftKeyOnMouseDown && DiagramUtils.isTextNode(draggableElem as SVGGraphicsElement)) {
return;
}
this.disablePanzoom(); // to avoid panning the whole SVG when moving or selecting a node
// change cursor style
const svg: HTMLElement = <HTMLElement>this.svgDraw?.node.firstElementChild?.parentElement;
svg.style.cursor = 'grabbing';
// check dragging vs. selection
this.shiftKeyOnMouseDown = !!(event as MouseEvent).shiftKey;
if (!this.shiftKeyOnMouseDown) {
// moving node
this.initializeDrag(draggableElem);
Expand All @@ -357,6 +365,10 @@ export class NetworkAreaDiagramViewer {
}

private handleDragEvent(event: Event) {
// check mouse button
if ((event as MouseEvent).button !== 0) {
return;
}
if (this.selectedElement && !this.shiftKeyOnMouseDown) {
event.preventDefault();
this.ctm = this.svgDraw?.node.getScreenCTM(); // used to compute SVG transformations
Expand Down Expand Up @@ -403,6 +415,10 @@ export class NetworkAreaDiagramViewer {
}

private handleEndDragSelectEvent(event: Event) {
// check mouse button
if ((event as MouseEvent).button !== 0) {
return;
}
// check if I moved or selected an element
if (this.selectedElement) {
if (!this.shiftKeyOnMouseDown) {
Expand Down

0 comments on commit e10b9e3

Please sign in to comment.