@@ -647,25 +647,43 @@ export const EditorUI = (props: EditorUIProps) => {
647
647
} )
648
648
649
649
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 ) {
651
652
// get the file name
652
653
const pastedCode = editor . getModel ( ) . getValueInRange ( e . range )
653
654
const pastedCodePrompt = intl . formatMessage ( { id : 'editor.PastedCodeSafety' } , { content :pastedCode } )
654
655
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
+
655
680
const modalContent : AppModal = {
656
681
id : 'newCodePasted' ,
657
682
title : "New code pasted" ,
658
683
okLabel : 'Ask RemixAI' ,
659
684
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
669
687
message : (
670
688
< div >
671
689
{ ' ' }
@@ -695,6 +713,18 @@ export const EditorUI = (props: EditorUIProps) => {
695
713
/>
696
714
</ div >
697
715
</ 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 >
698
728
</ div >
699
729
)
700
730
}
@@ -1048,6 +1078,15 @@ export const EditorUI = (props: EditorUIProps) => {
1048
1078
loadTypes ( monacoRef . current )
1049
1079
}
1050
1080
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
+
1051
1090
return (
1052
1091
< div className = "w-100 h-100 d-flex flex-column-reverse" >
1053
1092
0 commit comments