From 7408fcadcc7494b35b5313f997e0b100631dedcf Mon Sep 17 00:00:00 2001 From: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:12:20 +0200 Subject: [PATCH] Update remix-ui-editor.tsx --- .../editor/src/lib/remix-ui-editor.tsx | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) 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: (
{' '} @@ -696,6 +714,18 @@ export const EditorUI = (props: EditorUIProps) => { />
+ {/* Added Checkbox section below */} +
+ +
) } @@ -1049,6 +1079,15 @@ export const EditorUI = (props: EditorUIProps) => { loadTypes(monacoRef.current) } + const [showPasteWarning, setShowPasteWarning] = useState(() => { + try { + return localStorage.getItem(HIDE_PASTE_WARNING_KEY) !== 'true'; + } catch (e) { + console.error("Failed to access localStorage:", e); + return true; // Default to showing the warning if localStorage fails + } + }); + return (