feat: made jumpToNode select the node after focussing the editor
ref: N25B-450
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import {useReactFlow} from "@xyflow/react";
|
import {useReactFlow, useStoreApi} from "@xyflow/react";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import useFlowStore from "../VisProgStores.tsx";
|
import useFlowStore from "../VisProgStores.tsx";
|
||||||
import {
|
import {
|
||||||
warningSummary,
|
warningSummary,
|
||||||
type WarningSeverity, type EditorWarning
|
type WarningSeverity,
|
||||||
|
type EditorWarning, globalWarning
|
||||||
} from "./EditorWarnings.tsx";
|
} from "./EditorWarnings.tsx";
|
||||||
import styles from "./WarningSidebar.module.css";
|
import styles from "./WarningSidebar.module.css";
|
||||||
|
|
||||||
@@ -106,8 +107,11 @@ function WarningListItem(props: { warning: EditorWarning }) {
|
|||||||
|
|
||||||
function useJumpToNode() {
|
function useJumpToNode() {
|
||||||
const { getNode, setCenter } = useReactFlow();
|
const { getNode, setCenter } = useReactFlow();
|
||||||
|
const { addSelectedNodes } = useStoreApi().getState();
|
||||||
|
|
||||||
return (nodeId: string) => {
|
return (nodeId: string) => {
|
||||||
|
// user can't jump to global warning, so prevent further logic from running
|
||||||
|
if (nodeId === globalWarning) return;
|
||||||
const node = getNode(nodeId);
|
const node = getNode(nodeId);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
@@ -118,7 +122,10 @@ function useJumpToNode() {
|
|||||||
position!.x + width / 2,
|
position!.x + width / 2,
|
||||||
position!.y + height / 2,
|
position!.y + height / 2,
|
||||||
{ zoom: 2, duration: 300 }
|
{ zoom: 2, duration: 300 }
|
||||||
);
|
).then(() => {
|
||||||
|
// select the node
|
||||||
|
addSelectedNodes([nodeId]);
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user