Feat/saving code on language changes#282
Feat/saving code on language changes#282MahekVanjani611 wants to merge 2 commits intoopensource-society:mainfrom
Conversation
- Added a modern modal dialog for clearing code with improved CSS styling and user warning. - Implemented logic to preserve and restore code for each language when switching in the editor. Closes opensource-society#175
There was a problem hiding this comment.
Greptile Summary
This PR introduces two key user experience improvements to the CodeClip javascript executor:
-
Code preservation across language changes: The implementation adds a
languageCodesobject that automatically saves the current code when switching languages and restores either previously saved code or language-specific starter templates. This prevents users from losing their work when experimenting with different programming languages. -
Modern confirmation dialog for code clearing: Replaces the simple
confirm()dialog with a custom modal that features smooth CSS animations, better visual design, and clearer messaging about the destructive nature of clearing code.
The changes are contained entirely within javascript-executor.html and integrate well with the existing CodeMirror editor setup. The onLanguageChange() method handles the core logic for preserving and restoring code, while the enhanced clearEditor() method now shows the confirmation modal only when there's actual content to clear. The modal is implemented with modern CSS using flexbox, transitions, and a backdrop blur effect that matches contemporary web application patterns.
This enhancement addresses issue #175 and significantly improves the developer experience by making the editor behave more like professional online code editors that maintain state across language switches.
Confidence score: 3/5
- This PR has some potential issues that should be addressed before merging, particularly around CSS conflicts and code persistence.
- The score reflects concerns about CSS selector specificity conflicts between new modal button styles and existing button styles, plus the limitation that code is only stored in memory (lost on page refresh).
- The
javascript-executor.htmlfile needs careful review for the CSS button styling conflicts and consideration of whether the in-memory storage approach is sufficient for the use case.
1 file reviewed, 2 comments
| .btn-primary { | ||
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | ||
| color: #fff; | ||
| border: none; | ||
| font-weight: 600; | ||
| padding: 10px 22px; | ||
| border-radius: 8px; | ||
| font-size: 1rem; | ||
| box-shadow: 0 2px 8px rgba(102,126,234,0.12); | ||
| transition: background 0.2s, box-shadow 0.2s; | ||
| } | ||
| .btn-primary:hover { | ||
| background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); | ||
| box-shadow: 0 4px 16px rgba(102,126,234,0.18); | ||
| } | ||
| .btn-secondary { | ||
| background: #f8f9fa; | ||
| color: #764ba2; | ||
| border: 2px solid #e9ecef; | ||
| font-weight: 600; | ||
| padding: 10px 22px; | ||
| border-radius: 8px; | ||
| font-size: 1rem; | ||
| transition: background 0.2s, border-color 0.2s; | ||
| } | ||
| .btn-secondary:hover { | ||
| background: #e9ecef; | ||
| border-color: #764ba2; | ||
| } |
There was a problem hiding this comment.
logic: CSS selector conflicts: .btn-primary and .btn-secondary are redefined here but also exist at lines 192-211. The modal styles will override the existing button styles globally.
| .btn-primary { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: #fff; | |
| border: none; | |
| font-weight: 600; | |
| padding: 10px 22px; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| box-shadow: 0 2px 8px rgba(102,126,234,0.12); | |
| transition: background 0.2s, box-shadow 0.2s; | |
| } | |
| .btn-primary:hover { | |
| background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); | |
| box-shadow: 0 4px 16px rgba(102,126,234,0.18); | |
| } | |
| .btn-secondary { | |
| background: #f8f9fa; | |
| color: #764ba2; | |
| border: 2px solid #e9ecef; | |
| font-weight: 600; | |
| padding: 10px 22px; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| transition: background 0.2s, border-color 0.2s; | |
| } | |
| .btn-secondary:hover { | |
| background: #e9ecef; | |
| border-color: #764ba2; | |
| } | |
| .modal-actions .btn-primary { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: #fff; | |
| border: none; | |
| font-weight: 600; | |
| padding: 10px 22px; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| box-shadow: 0 2px 8px rgba(102,126,234,0.12); | |
| transition: background 0.2s, box-shadow 0.2s; | |
| } | |
| .modal-actions .btn-primary:hover { | |
| background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); | |
| box-shadow: 0 4px 16px rgba(102,126,234,0.18); | |
| } | |
| .modal-actions .btn-secondary { | |
| background: #f8f9fa; | |
| color: #764ba2; | |
| border: 2px solid #e9ecef; | |
| font-weight: 600; | |
| padding: 10px 22px; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| transition: background 0.2s, border-color 0.2s; | |
| } | |
| .modal-actions .btn-secondary:hover { | |
| background: #e9ecef; | |
| border-color: #764ba2; | |
| } |
|
@adityai0 kindly review this PR and let me know if any changes required |
Type of Change
Description
Motivation & Context
This change improves user experience by preventing accidental code loss and making it easier to work with multiple languages in the editor.
Related Issues
Closes #175
How Has This Been Tested?
Manual testing
Tested by switching languages, clearing code, and verifying the dialog and code restoration work as expected.
Screenshots / Media

Implementation Details
Checklist