Spaces:
Sleeping
Sleeping
fix: clear template on first edit using substring replace, not line matching
Browse files
app.py
CHANGED
|
@@ -418,21 +418,21 @@ def build_app() -> gr.Blocks:
|
|
| 418 |
|
| 419 |
# ---- Event wiring ----
|
| 420 |
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
}
|
| 425 |
|
| 426 |
def on_code_change(code: str, cleared: bool):
|
| 427 |
-
"""
|
| 428 |
if cleared:
|
| 429 |
return gr.update(), True
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
cleaned = "
|
|
|
|
| 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(
|