e.stopPropagation()}
data-to={target}
data-origin={origin}
diff --git a/src/components/DiagramFrame/SeqDiagram/MessageLayer/Block/Statement/InteractionAsync/Interaction-async.tsx b/src/components/DiagramFrame/SeqDiagram/MessageLayer/Block/Statement/InteractionAsync/Interaction-async.tsx
index 3bce6243..6a5cce71 100644
--- a/src/components/DiagramFrame/SeqDiagram/MessageLayer/Block/Statement/InteractionAsync/Interaction-async.tsx
+++ b/src/components/DiagramFrame/SeqDiagram/MessageLayer/Block/Statement/InteractionAsync/Interaction-async.tsx
@@ -65,6 +65,7 @@
* }
*
*/
+import { handleScrollAndHighlight } from "@/parser/IsCurrent";
import { cn } from "@/utils";
import { Comment } from "../Comment/Comment";
@@ -72,13 +73,15 @@ import { SelfInvocationAsync } from "./SelfInvocationAsync/SelfInvocationAsync";
import { Message } from "../Message";
import CommentClass from "@/components/Comment/Comment";
import { useAtomValue } from "jotai";
-import { cursorAtom, onElementClickAtom } from "@/store/Store";
+import { onElementClickAtom } from "@/store/Store";
import { CodeRange } from "@/parser/CodeRange";
import { useArrow } from "../useArrow";
-
-function isNullOrUndefined(value: any) {
- return value === null || value === undefined;
-}
+import {
+ cursorAtom,
+ enableCurrentElementHighlightAtom,
+ enableCurrentElementScrollIntoViewAtom,
+} from "@/store/Store";
+import { useEffect, useRef } from "react";
export const InteractionAsync = (props: {
context: any;
@@ -88,7 +91,6 @@ export const InteractionAsync = (props: {
number?: string;
className?: string;
}) => {
- const cursor = useAtomValue(cursorAtom);
const onElementClick = useAtomValue(onElementClickAtom);
const asyncMessage = props.context?.asyncMessage();
const signature = asyncMessage?.content()?.getFormattedText();
@@ -96,6 +98,42 @@ export const InteractionAsync = (props: {
const source = providedSource || props.origin;
const target = asyncMessage?.to()?.getFormattedText();
const isSelf = source === target;
+ const msgRef = useRef
(null);
+ const cursor = useAtomValue(cursorAtom);
+ const enableCurrentElementHighlight = useAtomValue(
+ enableCurrentElementHighlightAtom,
+ );
+ const enableCurrentElementScrollIntoView = useAtomValue(
+ enableCurrentElementScrollIntoViewAtom,
+ );
+ const isCurrent = () => {
+ const start = asyncMessage.start.start;
+ const stop = asyncMessage.stop.stop + 1;
+ if (
+ isNullOrUndefined(cursor) ||
+ isNullOrUndefined(start) ||
+ isNullOrUndefined(stop)
+ )
+ return false;
+ return cursor! >= start && cursor! <= stop;
+ };
+
+ function isNullOrUndefined(value: any) {
+ return value === null || value === undefined;
+ }
+
+ useEffect(() => {
+ return handleScrollAndHighlight({
+ ref: msgRef,
+ isCurrent: isCurrent(),
+ enableCurrentElementScrollIntoView,
+ enableCurrentElementHighlight,
+ });
+ }, [
+ isCurrent,
+ enableCurrentElementScrollIntoView,
+ enableCurrentElementHighlight,
+ ]);
const { translateX, interactionWidth, rightToLeft } = useArrow({
context: props.context,
@@ -107,19 +145,9 @@ export const InteractionAsync = (props: {
console.log(props.commentObj);
const messageClassNames = props.commentObj?.messageClassNames;
const messageTextStyle = props.commentObj?.messageStyle;
- const getIsCurrent = () => {
- const start = asyncMessage.start.start;
- const stop = asyncMessage.stop.stop + 1;
- if (
- isNullOrUndefined(cursor) ||
- isNullOrUndefined(start) ||
- isNullOrUndefined(stop)
- )
- return false;
- return cursor! >= start && cursor! <= stop;
- };
return (
{
const mode = useAtomValue(modeAtom);
const [code, setCode] = useAtom(codeAtom);
+ const cursor = useAtomValue(cursorAtom);
const onContentChange = useAtomValue(onContentChangeAtom);
+ const enableCurrentElementHighlight = useAtomValue(
+ enableCurrentElementHighlightAtom,
+ );
+ const enableCurrentElementScrollIntoView = useAtomValue(
+ enableCurrentElementScrollIntoViewAtom,
+ );
const formattedLabelText = formatText(props.labelText);
+ const labelRef = useRef(null);
+
+ const isCurrent =
+ cursor != null &&
+ cursor >= props.labelPosition[0] &&
+ cursor <= props.labelPosition[1] + 1;
+
+ useEffect(() => {
+ if (props.labelText) {
+ return handleScrollAndHighlight({
+ ref: labelRef,
+ isCurrent,
+ enableCurrentElementScrollIntoView,
+ enableCurrentElementHighlight,
+ });
+ }
+ }, [
+ isCurrent,
+ props.labelText,
+ enableCurrentElementScrollIntoView,
+ enableCurrentElementHighlight,
+ ]);
const replaceLabelText = (e: FocusEvent | KeyboardEvent | MouseEvent) => {
e.preventDefault();
@@ -61,6 +99,7 @@ export const MessageLabel = (props: {
return (