rafaym commited on
Commit
6f4f067
·
verified ·
1 Parent(s): 67af9b9

revert: restore original template value in code editor

Browse files
Files changed (1) hide show
  1. app.py +2 -59
app.py CHANGED
@@ -368,8 +368,7 @@ def build_app() -> gr.Blocks:
368
  label="Your Legesher code",
369
  language="python",
370
  lines=20,
371
- value="",
372
- elem_id="legesher-code-editor",
373
  )
374
 
375
  with gr.Row():
@@ -481,7 +480,7 @@ def build_app() -> gr.Blocks:
481
  )
482
 
483
  clear_btn.click(
484
- fn=lambda: ("", "", ""),
485
  outputs=[code_editor, stdin_input, run_output],
486
  )
487
 
@@ -498,62 +497,6 @@ def build_app() -> gr.Blocks:
498
  outputs=[submit_status],
499
  )
500
 
501
- # ---- JS: ghost text placeholder via overlay div (CodeMirror has no native placeholder API here) ----
502
- _GHOST_JS = """
503
- function() {
504
- const GHOST_TEXT = '# Write your solution here using Legesher\\n# Use native-language variable and function names';
505
-
506
- function mountGhost(cmEditor, view) {
507
- const scroller = cmEditor.querySelector('.cm-scroller');
508
- const firstLine = cmEditor.querySelector('.cm-line');
509
- if (!scroller || !firstLine) return null;
510
-
511
- const ls = window.getComputedStyle(firstLine);
512
- const sr = scroller.getBoundingClientRect();
513
- const lr = firstLine.getBoundingClientRect();
514
-
515
- const ghost = document.createElement('div');
516
- ghost.id = 'legesher-ghost';
517
- ghost.textContent = GHOST_TEXT;
518
- ghost.style.cssText = [
519
- 'position:absolute',
520
- 'pointer-events:none',
521
- 'white-space:pre',
522
- 'z-index:1',
523
- 'color:#9ca3af',
524
- 'font-family:' + ls.fontFamily,
525
- 'font-size:' + ls.fontSize,
526
- 'line-height:' + ls.lineHeight,
527
- 'top:' + (lr.top - sr.top + scroller.scrollTop) + 'px',
528
- 'left:' + (lr.left - sr.left) + 'px',
529
- ].join(';');
530
-
531
- scroller.style.position = 'relative';
532
- scroller.appendChild(ghost);
533
- return ghost;
534
- }
535
-
536
- function setup() {
537
- const cmEditor = document.querySelector('#legesher-code-editor .cm-editor');
538
- if (!cmEditor || !cmEditor.cmView) { setTimeout(setup, 300); return; }
539
-
540
- const view = cmEditor.cmView;
541
- let ghost = null;
542
-
543
- function update() {
544
- const empty = view.state.doc.toString().trim() === '';
545
- if (empty && !ghost) ghost = mountGhost(cmEditor, view);
546
- if (ghost) ghost.style.display = empty ? '' : 'none';
547
- }
548
-
549
- new MutationObserver(update).observe(cmEditor, { subtree: true, childList: true, characterData: true });
550
- setTimeout(update, 100);
551
- }
552
-
553
- setTimeout(setup, 800);
554
- }
555
- """
556
- app.load(fn=None, js=_GHOST_JS)
557
 
558
  return app
559
 
 
368
  label="Your Legesher code",
369
  language="python",
370
  lines=20,
371
+ value="# Write your solution here using Legesher\n# Use native-language variable and function names\n",
 
372
  )
373
 
374
  with gr.Row():
 
480
  )
481
 
482
  clear_btn.click(
483
+ fn=lambda: ("# Write your solution here using Legesher\n# Use native-language variable and function names\n", "", ""),
484
  outputs=[code_editor, stdin_input, run_output],
485
  )
486
 
 
497
  outputs=[submit_status],
498
  )
499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
 
501
  return app
502