@@ -9,7 +9,8 @@ const state = {
99 currentItem : null ,
1010 pyodide : null ,
1111 pyodideLoading : false ,
12- originalCode : ''
12+ originalCode : '' ,
13+ codeMirrorEditor : null
1314} ;
1415
1516// Pyodide Management
@@ -47,7 +48,7 @@ async function initPyodide() {
4748 }
4849}
4950
50- // Open Interactive Editor - Replace code section instead of modal
51+ // Open Interactive Editor - Replace code section
5152function openEditor ( pythonCode , problemTitle ) {
5253 state . originalCode = pythonCode ;
5354
@@ -74,10 +75,10 @@ function openEditor(pythonCode, problemTitle) {
7475 <button id="close-editor-btn-inline" class="inline-action-btn">✕ Close</button>
7576 </div>
7677 </div>
77- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; height: 500px ;">
78+ <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; height: 700px ;">
7879 <div style="display: flex; flex-direction: column; border: 1px solid #3e3e42; border-radius: 4px; overflow: hidden;">
79- <div style="padding: 0.5rem; background: #2d2d30; border-bottom: 1px solid #3e3e42; font-size: 0.85rem; color: #fff;">Code</div>
80- <textarea id="code-editor-inline" spellcheck="false" style="flex: 1; background: #1e1e1e; color: #d4d4d4; border: none; padding: 1rem; font-family: 'Consolas', 'Monaco', monospace; font-size: 14px; resize: none; outline: none;"> ${ escapeHtml ( pythonCode ) } </textarea >
80+ <div style="padding: 0.5rem; background: #2d2d30; border-bottom: 1px solid #3e3e42; font-size: 0.85rem; color: #fff;">Code Editor </div>
81+ <div id="codemirror-container" style="flex: 1; overflow: hidden;"></div >
8182 </div>
8283 <div style="display: flex; flex-direction: column; border: 1px solid #3e3e42; border-radius: 4px; overflow: hidden;">
8384 <div style="padding: 0.5rem; background: #2d2d30; border-bottom: 1px solid #3e3e42; font-size: 0.85rem; color: #fff; display: flex; justify-content: space-between;">
@@ -91,10 +92,29 @@ function openEditor(pythonCode, problemTitle) {
9192 <div style="padding: 0.5rem; background: #2d2d30; border-bottom: 1px solid #3e3e42; font-size: 0.85rem; color: #fff;">
9293 Test Input <span style="color: #888; font-weight: normal; margin-left: 0.5rem;">(available as input.txt or via input())</span>
9394 </div>
94- <textarea id="test-input-inline" placeholder="Paste test data here..." style="width: 100%; height: 100px ; background: #1e1e1e; color: #d4d4d4; border: none; padding: 1rem; font-family: 'Consolas', 'Monaco', monospace; font-size: 14px; resize: none; outline: none;"></textarea>
95+ <textarea id="test-input-inline" placeholder="Paste test data here..." style="width: 100%; height: 120px ; background: #1e1e1e; color: #d4d4d4; border: none; padding: 1rem; font-family: 'Consolas', 'Monaco', monospace; font-size: 14px; resize: none; outline: none;"></textarea>
9596 </div>
9697 ` ;
9798
99+ // Initialize CodeMirror
100+ const container = document . getElementById ( 'codemirror-container' ) ;
101+ if ( container && typeof CodeMirror !== 'undefined' ) {
102+ state . codeMirrorEditor = CodeMirror ( container , {
103+ value : pythonCode ,
104+ mode : 'python' ,
105+ theme : 'monokai' ,
106+ lineNumbers : true ,
107+ indentUnit : 4 ,
108+ tabSize : 4 ,
109+ indentWithTabs : false ,
110+ lineWrapping : true ,
111+ autofocus : true
112+ } ) ;
113+
114+ // Set height
115+ state . codeMirrorEditor . setSize ( '100%' , '100%' ) ;
116+ }
117+
98118 // Attach event listeners
99119 document . getElementById ( 'run-code-btn-inline' ) ?. addEventListener ( 'click' , runCodeInline ) ;
100120 document . getElementById ( 'reset-code-btn-inline' ) ?. addEventListener ( 'click' , resetCodeInline ) ;
@@ -111,13 +131,19 @@ function openEditor(pythonCode, problemTitle) {
111131
112132// Close inline editor and restore original view
113133function closeEditorInline ( ) {
134+ // Cleanup CodeMirror
135+ if ( state . codeMirrorEditor ) {
136+ state . codeMirrorEditor . toTextArea ( ) ;
137+ state . codeMirrorEditor = null ;
138+ }
139+
114140 // Reload the problem view to restore everything
115141 renderProblem ( ) ;
116142}
117143
118144// Run Code (inline version)
119145async function runCodeInline ( ) {
120- const code = document . getElementById ( 'code-editor-inline' ) . value ;
146+ const code = state . codeMirrorEditor ? state . codeMirrorEditor . getValue ( ) : '' ;
121147 const testInput = document . getElementById ( 'test-input-inline' ) . value ;
122148 const output = document . getElementById ( 'code-output-inline' ) ;
123149 const runBtn = document . getElementById ( 'run-code-btn-inline' ) ;
@@ -210,26 +236,13 @@ __builtins__.input = mock_input
210236
211237// Reset Code (inline version)
212238function resetCodeInline ( ) {
213- document . getElementById ( 'code-editor-inline' ) . value = state . originalCode ;
239+ if ( state . codeMirrorEditor ) {
240+ state . codeMirrorEditor . setValue ( state . originalCode ) ;
241+ }
214242 document . getElementById ( 'code-output-inline' ) . innerHTML = '' ;
215243 document . getElementById ( 'test-input-inline' ) . value = '' ;
216244}
217245
218- // Download Code
219- function downloadCode ( ) {
220- const editor = document . getElementById ( 'code-editor-inline' ) ;
221- if ( ! editor ) return ;
222-
223- const code = editor . value ;
224- const blob = new Blob ( [ code ] , { type : 'text/plain' } ) ;
225- const url = URL . createObjectURL ( blob ) ;
226- const a = document . createElement ( 'a' ) ;
227- a . href = url ;
228- a . download = 'solution.py' ;
229- a . click ( ) ;
230- URL . revokeObjectURL ( url ) ;
231- }
232-
233246// Utility
234247function getRepoPath ( ) {
235248 const parts = window . location . pathname . split ( '/' ) ;
@@ -717,17 +730,6 @@ window.addEventListener('hashchange', () => {
717730 window . runCodeInline = runCodeInline ;
718731 window . closeEditorInline = closeEditorInline ;
719732 window . resetCodeInline = resetCodeInline ;
720- window . downloadCode = downloadCode ;
721-
722- // Setup modal event listeners (legacy - not used anymore but kept for safety)
723- const modal = document . getElementById ( 'code-editor-modal' ) ;
724- if ( modal ) {
725- modal . addEventListener ( 'click' , ( e ) => {
726- if ( e . target . id === 'code-editor-modal' ) {
727- modal . style . display = 'none' ;
728- }
729- } ) ;
730- }
731733
732734 await loadPlatforms ( ) ;
733735
0 commit comments