11import { useState , useCallback } from "react"
2- import { vscode } from "@src/utils/vscode"
32import { useCopyToClipboard } from "@src/utils/clipboard"
43import { useAppTranslation } from "@src/i18n/TranslationContext"
54import { MermaidActionButtons } from "./MermaidActionButtons"
@@ -16,7 +15,7 @@ export interface MermaidButtonProps {
1615 children : React . ReactNode
1716}
1817
19- export function MermaidButton ( { containerRef, code, isLoading, svgToPng , children } : MermaidButtonProps ) {
18+ export function MermaidButton ( { containerRef, code, isLoading, children } : MermaidButtonProps ) {
2019 const [ showModal , setShowModal ] = useState ( false )
2120 const [ zoomLevel , setZoomLevel ] = useState ( 1 )
2221 const [ copyFeedback , setCopyFeedback ] = useState ( false )
@@ -38,30 +37,19 @@ export function MermaidButton({ containerRef, code, isLoading, svgToPng, childre
3837 }
3938
4039 /**
41- * Copies the diagram as PNG to clipboard
40+ * Copies the diagram text to clipboard
4241 */
4342 const handleCopy = async ( e : React . MouseEvent ) => {
4443 e . stopPropagation ( )
45- if ( ! containerRef . current ) return
46- const svgEl = containerRef . current . querySelector ( "svg" )
47- if ( ! svgEl ) return
4844
4945 try {
50- const pngDataUrl = await svgToPng ( svgEl )
51-
52- // Send the image to the extension to handle copying
53- // Reuse the openImage message type with an additional parameter
54- vscode . postMessage ( {
55- type : "openImage" ,
56- text : pngDataUrl ,
57- values : { action : "copy" } , // Add this parameter to indicate copy action
58- } )
46+ await copyWithFeedback ( code , e )
5947
6048 // Show feedback
6149 setCopyFeedback ( true )
6250 setTimeout ( ( ) => setCopyFeedback ( false ) , 2000 )
6351 } catch ( err ) {
64- console . error ( "Error copying image :" , err instanceof Error ? err . message : String ( err ) )
52+ console . error ( "Error copying text :" , err instanceof Error ? err . message : String ( err ) )
6553 }
6654 }
6755
0 commit comments