Skip to content

Commit

Permalink
Replaced blocklyDraggable check w/parent != blocklyBlockCanvas (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
rshaker authored May 30, 2024
1 parent 19379ee commit a0c8238
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,21 @@ export class MultiselectPlugin {
return this.blockly;
}

protected getDraggableElement(element: HTMLElement, topLevel: boolean = true): SVGElement | null {
while (element && this.blocklyBlockCanvas.contains(element)) {
// Find either the 1st, or top-level block
if (
element.classList.contains("blocklyDraggable") &&
(!topLevel || element.parentElement === this.blocklyBlockCanvas)
) {
return element as unknown as SVGElement;
/**
* Given an element, return the first ancestor of element (or self) that is a child of blocklyBlockCanvas.
* If the element is not a descendant of the blocklyBlockCanvas, return null.
* Otherwise, return the first ancestor of element (or self) that is a child of blocklyBlockCanvas.
*/
protected getDraggableElement(element: HTMLElement): SVGElement | null {
if (element === null || !this.blocklyBlockCanvas.contains(element)) {
return null;
} else {
let currElement = element;
while (currElement.parentElement !== this.blocklyBlockCanvas) {
currElement = currElement.parentElement;
}
element = element.parentElement;
return currElement as unknown as SVGElement;
}
return null; // Shouldn't happen?
}

protected getHtmlElement(name: string, maxWait = 5000): Promise<HTMLElement> {
Expand Down Expand Up @@ -299,7 +302,7 @@ export class MultiselectPlugin {

protected handlePointerDown(e: PointerEvent) {
const elementBeneath = document.elementFromPoint(e.clientX, e.clientY) as HTMLElement;
const topElement = this.getDraggableElement(elementBeneath, true);
const topElement = this.getDraggableElement(elementBeneath);
const blockId = topElement ? topElement.getAttribute("data-id") : null;

// Handle click on background
Expand Down Expand Up @@ -501,10 +504,10 @@ export class MultiselectPlugin {
this.filterEnable(svgElement, selected);
}

selectAll(all: boolean) {
selectAll(select: boolean) {
const blocks = this.workspace.getTopBlocks(false);
blocks.forEach((block) => {
this.select(block.id, all);
this.select(block.id, select);
});
}

Expand Down

0 comments on commit a0c8238

Please sign in to comment.