Skip to content

Commit fb5e15d

Browse files
committed
scroll to selected element on tab load/activate
1 parent e5ab108 commit fb5e15d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Frontend/src/components/messages2/SequenceDiagram/HandlersComponent.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { HandlerState } from "@/resources/SequenceDiagram/Handler";
3-
import { computed, ref } from "vue";
3+
import { computed, onActivated, ref, watch } from "vue";
44
import { Direction } from "@/resources/SequenceDiagram/RoutedMessage";
55
import { useSequenceDiagramStore } from "@/stores/SequenceDiagramStore";
66
import { storeToRefs } from "pinia";
@@ -13,6 +13,14 @@ const store = useSequenceDiagramStore();
1313
const { handlers, endpointCentrePoints, highlightId, selectedId } = storeToRefs(store);
1414
1515
const messageTypeRefs = ref<SVGTextElement[]>([]);
16+
const hasMadeVisible = ref(false);
17+
const selectedElement = ref<SVGElement>();
18+
//reset values to allow scroll to element on switching back to this tab
19+
onActivated(() => {
20+
hasMadeVisible.value = false;
21+
if (selectedElement.value) scrollToIfSelected(selectedElement.value, selectedId.value);
22+
});
23+
watch(selectedId, () => (selectedElement.value = undefined));
1624
1725
const handlerItems = computed(() => {
1826
let nextY = 0;
@@ -80,10 +88,19 @@ const handlerItems = computed(() => {
8088
function setMessageTypeRef(el: SVGTextElement, index: number) {
8189
if (el) messageTypeRefs.value[index] = el;
8290
}
91+
92+
function scrollToIfSelected(el: SVGElement, handlerId: string | undefined) {
93+
if (!hasMadeVisible.value && el && handlerId === selectedId.value) {
94+
hasMadeVisible.value = true;
95+
selectedElement.value = el;
96+
//can't be done immediately since the sequence diagram hasn't completed layout yet
97+
setTimeout(() => selectedElement.value!.scrollIntoView(false), 30);
98+
}
99+
}
83100
</script>
84101

85102
<template>
86-
<g v-for="(handler, i) in handlerItems" :key="`${handler.id}###${handler.endpointName}`" :transform="`translate(${handler.left}, ${handler.y})`">
103+
<g v-for="(handler, i) in handlerItems" :key="`${handler.id}###${handler.endpointName}`" :ref="(el) => scrollToIfSelected(el as SVGElement, handler.incomingId)" :transform="`translate(${handler.left}, ${handler.y})`">
87104
<!--Handler Activation Box-->
88105
<g :ref="(el) => handler.setUIRef(el as SVGElement)" class="activation-box">
89106
<rect

0 commit comments

Comments
 (0)