Skip to content

Commit 2c41dea

Browse files
gap-editorAniket-Engg
authored andcommitted
Update remix-ui-editor.tsx
1 parent beccde3 commit 2c41dea

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,25 +647,43 @@ export const EditorUI = (props: EditorUIProps) => {
647647
})
648648

649649
editor.onDidPaste(async (e) => {
650-
if (!pasteCodeRef.current && e && e.range && e.range.startLineNumber >= 0 && e.range.endLineNumber >= 0 && e.range.endLineNumber - e.range.startLineNumber > 10) {
650+
// Only show the modal if the user hasn't opted out
651+
if (showPasteWarning && !pasteCodeRef.current && e && e.range && e.range.startLineNumber >= 0 && e.range.endLineNumber >= 0 && e.range.endLineNumber - e.range.startLineNumber > 10) {
651652
// get the file name
652653
const pastedCode = editor.getModel().getValueInRange(e.range)
653654
const pastedCodePrompt = intl.formatMessage({ id: 'editor.PastedCodeSafety' }, { content:pastedCode })
654655

656+
// State for the checkbox inside this specific modal instance
657+
let dontShowAgainChecked = false;
658+
659+
const handleClose = (askAI = false) => {
660+
if (dontShowAgainChecked) {
661+
try {
662+
localStorage.setItem(HIDE_PASTE_WARNING_KEY, 'true');
663+
setShowPasteWarning(false); // Update state to prevent future modals in this session
664+
} catch (e) {
665+
console.error("Failed to write to localStorage:", e);
666+
}
667+
}
668+
if (askAI) {
669+
// Proceed with the original okFn logic
670+
(async () => {
671+
await props.plugin.call('popupPanel', 'showPopupPanel', true)
672+
setTimeout(async () => {
673+
props.plugin.call('remixAI', 'chatPipe', 'vulnerability_check', pastedCodePrompt)
674+
}, 500)
675+
_paq.push(['trackEvent', 'ai', 'remixAI', 'vulnerability_check_pasted_code'])
676+
})();
677+
}
678+
};
679+
655680
const modalContent: AppModal = {
656681
id: 'newCodePasted',
657682
title: "New code pasted",
658683
okLabel: 'Ask RemixAI',
659684
cancelLabel: 'Close',
660-
cancelFn: () => {},
661-
okFn: async () => {
662-
await props.plugin.call('popupPanel', 'showPopupPanel', true)
663-
setTimeout(async () => {
664-
props.plugin.call('remixAI', 'chatPipe', 'vulnerability_check', pastedCodePrompt)
665-
}, 500)
666-
// add matamo event
667-
_paq.push(['trackEvent', 'ai', 'remixAI', 'vulnerability_check_pasted_code'])
668-
},
685+
cancelFn: () => handleClose(false), // Pass false for askAI
686+
okFn: () => handleClose(true), // Pass true for askAI
669687
message: (
670688
<div>
671689
{' '}
@@ -695,6 +713,18 @@ export const EditorUI = (props: EditorUIProps) => {
695713
/>
696714
</div>
697715
</div>
716+
{/* Added Checkbox section below */}
717+
<div className="mt-3">
718+
<label htmlFor="donotshowagain" className="text-dark">
719+
<input
720+
type="checkbox"
721+
id="donotshowagain"
722+
className="mr-2"
723+
onChange={(e) => dontShowAgainChecked = e.target.checked}
724+
/>
725+
<FormattedMessage id="editor.doNotShowAgain" defaultMessage="Do not show this warning again" /> {/* Consider adding this to locale files */}
726+
</label>
727+
</div>
698728
</div>
699729
)
700730
}
@@ -1048,6 +1078,15 @@ export const EditorUI = (props: EditorUIProps) => {
10481078
loadTypes(monacoRef.current)
10491079
}
10501080

1081+
const [showPasteWarning, setShowPasteWarning] = useState(() => {
1082+
try {
1083+
return localStorage.getItem(HIDE_PASTE_WARNING_KEY) !== 'true';
1084+
} catch (e) {
1085+
console.error("Failed to access localStorage:", e);
1086+
return true; // Default to showing the warning if localStorage fails
1087+
}
1088+
});
1089+
10511090
return (
10521091
<div className="w-100 h-100 d-flex flex-column-reverse">
10531092

0 commit comments

Comments
 (0)