From b0d48b8463d4cfbaeeead1fa1f7306d7206256a4 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Wed, 6 Oct 2021 11:22:00 +0200 Subject: [PATCH] fix: reset editor display on user interaction (#43730) If the user types in the editor or pushes the reset button, the lower jaw now resets to the default state. --- .../templates/Challenges/classic/editor.tsx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/client/src/templates/Challenges/classic/editor.tsx b/client/src/templates/Challenges/classic/editor.tsx index ff1933c913..c8f7637a25 100644 --- a/client/src/templates/Challenges/classic/editor.tsx +++ b/client/src/templates/Challenges/classic/editor.tsx @@ -968,6 +968,35 @@ const Editor = (props: EditorProps): JSX.Element => { editor?.focus(); if (isProjectStep() && editor) { showEditableRegion(editor); + + // resetting test output + // TODO: DRY this - createOutputNode doesn't also need to set this up. + const testButton = document.getElementById('test-button'); + if (testButton) { + testButton.innerHTML = 'Check Your Code (Ctrl + Enter)'; + testButton.onclick = () => { + props.executeChallenge(); + }; + } + const testStatus = document.getElementById('test-status'); + if (testStatus) { + testStatus.innerHTML = ''; + } + const testOutput = document.getElementById('test-output'); + if (testOutput) { + testOutput.innerHTML = ''; + } + // resetting margin decorations + // TODO: this should be done via the decorator api, not by manipulating + // the DOM + const editableRegionDecorators = document.getElementsByClassName( + 'myEditableLineDecoration' + ); + if (editableRegionDecorators.length > 0) { + for (const i of editableRegionDecorators) { + i.classList.remove('tests-passed'); + } + } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.challengeFiles]); @@ -990,6 +1019,8 @@ const Editor = (props: EditorProps): JSX.Element => { }; } + // TODO: this should be done via the decorator api, not by manipulating + // the DOM const editableRegionDecorators = document.getElementsByClassName( 'myEditableLineDecoration' );