Skip to content

Commit b0d48b8

Browse files
fix: reset editor display on user interaction (freeCodeCamp#43730)
If the user types in the editor or pushes the reset button, the lower jaw now resets to the default state.
1 parent 4ffc06e commit b0d48b8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

client/src/templates/Challenges/classic/editor.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,35 @@ const Editor = (props: EditorProps): JSX.Element => {
968968
editor?.focus();
969969
if (isProjectStep() && editor) {
970970
showEditableRegion(editor);
971+
972+
// resetting test output
973+
// TODO: DRY this - createOutputNode doesn't also need to set this up.
974+
const testButton = document.getElementById('test-button');
975+
if (testButton) {
976+
testButton.innerHTML = 'Check Your Code (Ctrl + Enter)';
977+
testButton.onclick = () => {
978+
props.executeChallenge();
979+
};
980+
}
981+
const testStatus = document.getElementById('test-status');
982+
if (testStatus) {
983+
testStatus.innerHTML = '';
984+
}
985+
const testOutput = document.getElementById('test-output');
986+
if (testOutput) {
987+
testOutput.innerHTML = '';
988+
}
989+
// resetting margin decorations
990+
// TODO: this should be done via the decorator api, not by manipulating
991+
// the DOM
992+
const editableRegionDecorators = document.getElementsByClassName(
993+
'myEditableLineDecoration'
994+
);
995+
if (editableRegionDecorators.length > 0) {
996+
for (const i of editableRegionDecorators) {
997+
i.classList.remove('tests-passed');
998+
}
999+
}
9711000
}
9721001
// eslint-disable-next-line react-hooks/exhaustive-deps
9731002
}, [props.challengeFiles]);
@@ -990,6 +1019,8 @@ const Editor = (props: EditorProps): JSX.Element => {
9901019
};
9911020
}
9921021

1022+
// TODO: this should be done via the decorator api, not by manipulating
1023+
// the DOM
9931024
const editableRegionDecorators = document.getElementsByClassName(
9941025
'myEditableLineDecoration'
9951026
);

0 commit comments

Comments
 (0)