Skip to content

Commit 23f1e17

Browse files
committed
fix paste opt out
1 parent 5bc7cfe commit 23f1e17

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,19 @@ export const EditorUI = (props: EditorUIProps) => {
650650
})
651651

652652
editor.onDidPaste(async (e) => {
653+
const shouldShowWarning = localStorage.getItem(HIDE_PASTE_WARNING_KEY) !== 'true';
653654
// Only show the modal if the user hasn't opted out
654-
if (showPasteWarning && !pasteCodeRef.current && e && e.range && e.range.startLineNumber >= 0 && e.range.endLineNumber >= 0 && e.range.endLineNumber - e.range.startLineNumber > 10) {
655+
if (shouldShowWarning && !pasteCodeRef.current && e && e.range && e.range.startLineNumber >= 0 && e.range.endLineNumber >= 0 && e.range.endLineNumber - e.range.startLineNumber > 10) {
655656
// get the file name
656657
const pastedCode = editor.getModel().getValueInRange(e.range)
657658
const pastedCodePrompt = intl.formatMessage({ id: 'editor.PastedCodeSafety' }, { content:pastedCode })
658659

659660
// State for the checkbox inside this specific modal instance
660661
let dontShowAgainChecked = false;
661-
662662
const handleClose = (askAI = false) => {
663663
if (dontShowAgainChecked) {
664664
try {
665665
localStorage.setItem(HIDE_PASTE_WARNING_KEY, 'true');
666-
setShowPasteWarning(false); // Update state to prevent future modals in this session
667666
} catch (e) {
668667
console.error("Failed to write to localStorage:", e);
669668
}
@@ -1081,15 +1080,6 @@ export const EditorUI = (props: EditorUIProps) => {
10811080
loadTypes(monacoRef.current)
10821081
}
10831082

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

0 commit comments

Comments
 (0)