diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index 3ba8051..386e80e 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -27,18 +27,23 @@ export default function ChatPanel({ const { loadDiagram: onDisplayChart, handleExport: onExport, + handleExportWithoutHistory, resolverRef, chartXML, clearDiagram, } = useDiagram(); - const onFetchChart = () => { + const onFetchChart = (saveToHistory = true) => { return Promise.race([ new Promise((resolve) => { if (resolverRef && "current" in resolverRef) { resolverRef.current = resolve; } - onExport(); + if (saveToHistory) { + onExport(); + } else { + handleExportWithoutHistory(); + } }), new Promise((_, reject) => setTimeout( @@ -87,7 +92,8 @@ export default function ChatPanel({ let currentXml = ""; try { - currentXml = await onFetchChart(); + // Fetch without saving to history - edit_diagram shouldn't create history entry + currentXml = await onFetchChart(false); const { replaceXMLParts } = await import("@/lib/utils"); const editedXml = replaceXMLParts(currentXml, edits); diff --git a/contexts/diagram-context.tsx b/contexts/diagram-context.tsx index d8a3362..f1ecf4c 100644 --- a/contexts/diagram-context.tsx +++ b/contexts/diagram-context.tsx @@ -10,6 +10,7 @@ interface DiagramContextType { diagramHistory: { svg: string; xml: string }[]; loadDiagram: (chart: string) => void; handleExport: () => void; + handleExportWithoutHistory: () => void; resolverRef: React.Ref<((value: string) => void) | null>; drawioRef: React.Ref; handleDiagramExport: (data: any) => void; @@ -42,6 +43,15 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) { } }; + const handleExportWithoutHistory = () => { + if (drawioRef.current) { + // Export without saving to history (for edit_diagram fetching current state) + drawioRef.current.exportDiagram({ + format: "xmlsvg", + }); + } + }; + const loadDiagram = (chart: string) => { if (drawioRef.current) { drawioRef.current.load({ @@ -124,6 +134,7 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) { diagramHistory, loadDiagram, handleExport, + handleExportWithoutHistory, resolverRef, drawioRef, handleDiagramExport,