diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 35b23bc5541..a2204d27c8e 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -648,25 +648,43 @@ export const EditorUI = (props: EditorUIProps) => { }) editor.onDidPaste(async (e) => { - if (!pasteCodeRef.current && e && e.range && e.range.startLineNumber >= 0 && e.range.endLineNumber >= 0 && e.range.endLineNumber - e.range.startLineNumber > 10) { + // Only show the modal if the user hasn't opted out + if (showPasteWarning && !pasteCodeRef.current && e && e.range && e.range.startLineNumber >= 0 && e.range.endLineNumber >= 0 && e.range.endLineNumber - e.range.startLineNumber > 10) { // get the file name const pastedCode = editor.getModel().getValueInRange(e.range) const pastedCodePrompt = intl.formatMessage({ id: 'editor.PastedCodeSafety' }, { content:pastedCode }) + // State for the checkbox inside this specific modal instance + let dontShowAgainChecked = false; + + const handleClose = (askAI = false) => { + if (dontShowAgainChecked) { + try { + localStorage.setItem(HIDE_PASTE_WARNING_KEY, 'true'); + setShowPasteWarning(false); // Update state to prevent future modals in this session + } catch (e) { + console.error("Failed to write to localStorage:", e); + } + } + if (askAI) { + // Proceed with the original okFn logic + (async () => { + await props.plugin.call('popupPanel', 'showPopupPanel', true) + setTimeout(async () => { + props.plugin.call('remixAI', 'chatPipe', 'vulnerability_check', pastedCodePrompt) + }, 500) + _paq.push(['trackEvent', 'ai', 'remixAI', 'vulnerability_check_pasted_code']) + })(); + } + }; + const modalContent: AppModal = { id: 'newCodePasted', title: "New code pasted", okLabel: 'Ask RemixAI', cancelLabel: 'Close', - cancelFn: () => {}, - okFn: async () => { - await props.plugin.call('popupPanel', 'showPopupPanel', true) - setTimeout(async () => { - props.plugin.call('remixAI', 'chatPipe', 'vulnerability_check', pastedCodePrompt) - }, 500) - // add matamo event - _paq.push(['trackEvent', 'ai', 'remixAI', 'vulnerability_check_pasted_code']) - }, + cancelFn: () => handleClose(false), // Pass false for askAI + okFn: () => handleClose(true), // Pass true for askAI message: (