rafaym commited on
Commit
d82e5a0
·
verified ·
1 Parent(s): 63c3a31

fix: clear template on first edit using substring replace, not line matching

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -418,21 +418,21 @@ def build_app() -> gr.Blocks:
418
 
419
  # ---- Event wiring ----
420
 
421
- _TEMPLATE_LINES = {
422
- "# Write your solution here using Legesher",
423
- "# Use native-language variable and function names",
424
- }
425
 
426
  def on_code_change(code: str, cleared: bool):
427
- """Strip template comment lines on the user's very first edit, then never again."""
428
  if cleared:
429
  return gr.update(), True
430
- lines = code.split("\n")
431
- filtered = [l for l in lines if l.strip() not in _TEMPLATE_LINES]
432
- # Remove leading blank lines left behind
433
- while filtered and not filtered[0].strip():
434
- filtered.pop(0)
435
- cleaned = "\n".join(filtered)
 
436
  return cleaned, True
437
 
438
  code_editor.change(
 
418
 
419
  # ---- Event wiring ----
420
 
421
+ _T1 = "# Write your solution here using Legesher"
422
+ _T2 = "# Use native-language variable and function names"
423
+ _TEMPLATE = f"{_T1}\n{_T2}\n"
 
424
 
425
  def on_code_change(code: str, cleared: bool):
426
+ """On the user's first real edit, strip the template strings then never run again."""
427
  if cleared:
428
  return gr.update(), True
429
+ # Nothing typed yet — template still untouched
430
+ if code.strip() in ("", _T1, _T2, f"{_T1}\n{_T2}"):
431
+ return gr.update(), False
432
+ # Strip the two template lines wherever they appear via substring replace
433
+ cleaned = code.replace(_T1 + "\n", "").replace(_T2 + "\n", "")
434
+ cleaned = cleaned.replace(_T1, "").replace(_T2, "")
435
+ cleaned = cleaned.lstrip("\n")
436
  return cleaned, True
437
 
438
  code_editor.change(