Skip to content

Commit

Permalink
fix: finishing packet sending when packet is selected (#48)
Browse files Browse the repository at this point in the history
An error is thrown when a packet’s sending process ends with the packet
being selected. The error was resolved by deselecting the packet once
its sending process is complete.
  • Loading branch information
Manuel-Pol authored Nov 14, 2024
1 parent 8d89b79 commit aea184d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/types/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Ticker,
} from "pixi.js";
import { Edge, Position } from "./edge";
import { selectElement } from "./viewportManager";
import { deselectElement, isSelected, selectElement } from "./viewportManager";
import { circleGraphicsContext, Colors, ZIndexLevels } from "../utils";
import { RightBar } from "../index";

Expand Down Expand Up @@ -116,6 +116,9 @@ export class Packet extends Graphics {
this.removeFromParent();
if (this.currentPath.length == 0) {
ticker.remove(this.animationTick, this);
if (isSelected(this)) {
deselectElement();
}
this.destroy();
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/viewportManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export function refreshElement() {
}
}

export function isSelected(element: Device | Edge | Packet) {
return element === selectedElement;
}

document.addEventListener("keydown", (event) => {
if (event.key === "Delete" || event.key === "Backspace") {
if (selectedElement) {
Expand Down

0 comments on commit aea184d

Please sign in to comment.