Skip to content

Commit 9b0197a

Browse files
authored
Persist selections between layers (#241)
close #235
1 parent ce8f9db commit 9b0197a

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

src/handlers/layerSelectorHandler.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { GlobalContext } from "../context";
22
import { LeftBar } from "../graphics/left_bar";
33
import { layerToName } from "../types/layer";
4-
import { deselectElement, saveToLocalStorage } from "../types/viewportManager";
4+
import {
5+
deselectElement,
6+
isSelectedElementVisible,
7+
saveToLocalStorage,
8+
} from "../types/viewportManager";
59
import {
610
Dropdown,
711
DropdownOption,
@@ -82,10 +86,12 @@ export class LayerHandler {
8286
this.ctx.changeLayer(selectedLayer);
8387
saveToLocalStorage(this.ctx);
8488
this.leftBar.setButtonsByLayer(selectedLayer);
85-
deselectElement();
89+
if (!isSelectedElementVisible()) {
90+
deselectElement();
91+
}
8692

8793
if (showAlert) {
88-
showSuccess(ALERT_MESSAGES.LAYER_CHANGED, 7000);
94+
showSuccess(ALERT_MESSAGES.LAYER_CHANGED, 5000);
8995
}
9096
}
9197
}

src/types/edge.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ export class Edge extends Graphics {
156156
this.visible = device1CanReachVisibleDevice && device2CanReachVisibleDevice;
157157
}
158158

159+
isVisible(): boolean {
160+
return this.visible;
161+
}
162+
159163
/**
160164
* Updates the position of an edge connecting two devices, taking into account their visibility
161165
* and dimensions. If a device is visible, the edge will leave a space around the device's center

src/types/packet.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ export class Packet extends Graphics {
133133
return rawPacket.getDetails(layer);
134134
}
135135

136+
isVisible(): boolean {
137+
return this.visible;
138+
}
139+
136140
getPacketLocation(): PacketLocation {
137141
return {
138142
startId: this.currStart,

src/types/view-devices/vDevice.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export abstract class ViewDevice extends Container {
205205
this.visible = layerIncluded(this.getLayer(), this.viewgraph.getLayer());
206206
}
207207

208+
isVisible(): boolean {
209+
return this.visible;
210+
}
211+
208212
// Function to add the ID label to the device
209213
addDeviceIdLabel() {
210214
const textStyle = new TextStyle({

src/types/viewportManager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export function deselectElement() {
4848
}
4949
}
5050

51+
export function isSelectedElementVisible(): boolean {
52+
if (selectedElement) {
53+
return selectedElement.isVisible();
54+
}
55+
return false;
56+
}
57+
5158
export function refreshElement() {
5259
if (selectedElement) {
5360
// Deselect the current element and then reselect it to refresh

0 commit comments

Comments
 (0)