@@ -56,6 +56,8 @@ var pyTestInputCodeMirror; // CodeMirror object that contains the test code
5656
5757
5858$ ( document ) . ready ( function ( ) {
59+ useCodeMirror = true ; // set global defined in opt-frontend-common.js
60+
5961 problemName = window . location . search ;
6062 if ( ! problemName ) {
6163 alert ( "Error! Pass in a valid problem name in the url as '?<problem name>'" ) ;
@@ -162,36 +164,34 @@ $(document).ready(function() {
162164 jumpToEnd : true ,
163165 }
164166
167+ function f1 ( errorLineNo ) {
168+ pyInputCodeMirror . removeLineClass ( errorLineNo , null , 'errorLine' ) ; // reset line back to normal
169+ pyInputCodeMirror . off ( 'change' , f1 ) ;
170+ }
171+ function f2 ( errorLineNo ) {
172+ pyTestInputCodeMirror . removeLineClass ( errorLineNo , null , 'errorLine' ) ; // reset line back to normal
173+ pyTestInputCodeMirror . off ( 'change' , f2 ) ;
174+ }
175+
165176 function handleUncaughtExceptionFunc ( trace ) {
166177 if ( trace . length == 1 ) {
167178 var errorLineNo = trace [ 0 ] . line - 1 ; /* CodeMirror lines are zero-indexed */
168179 if ( errorLineNo !== undefined ) {
169-
170180 if ( errorLineNo < nCodeLines ) {
171181 // highlight the faulting line in pyInputCodeMirror
172182 pyInputCodeMirror . focus ( ) ;
173183 pyInputCodeMirror . setCursor ( errorLineNo , 0 ) ;
174- // TODO: refactor to use new CodeMirror version
175- pyInputCodeMirror . setLineClass ( errorLineNo , null , 'errorLine' ) ;
176-
177- pyInputCodeMirror . setOption ( 'onChange' , function ( ) {
178- pyInputCodeMirror . setLineClass ( errorLineNo , null , null ) ; // reset line back to normal
179- pyInputCodeMirror . setOption ( 'onChange' , null ) ; // cancel
180- } ) ;
184+ pyInputCodeMirror . addLineClass ( errorLineNo , null , 'errorLine' ) ;
185+ pyInputCodeMirror . on ( 'change' , f1 . bind ( errorLineNo ) ) ;
181186 }
182187 else {
183188 // instead highlight the faulting line in pyTestInputCodeMirror
184189 errorLineNo -= nCodeLines ;
185190
186- // TODO: refactor to use new CodeMirror version
187191 pyTestInputCodeMirror . focus ( ) ;
188192 pyTestInputCodeMirror . setCursor ( errorLineNo , 0 ) ;
189- pyTestInputCodeMirror . setLineClass ( errorLineNo , null , 'errorLine' ) ;
190-
191- pyTestInputCodeMirror . setOption ( 'onChange' , function ( ) {
192- pyTestInputCodeMirror . setLineClass ( errorLineNo , null , null ) ;
193- pyTestInputCodeMirror . setOption ( 'onChange' , null ) ; // cancel
194- } ) ;
193+ pyTestInputCodeMirror . addLineClass ( errorLineNo , null , 'errorLine' ) ;
194+ pyTestInputCodeMirror . on ( 'change' , f2 . bind ( errorLineNo ) ) ;
195195 }
196196 }
197197
@@ -277,13 +277,6 @@ $(document).ready(function() {
277277 } ,
278278 "json" ) ;
279279
280- // stent
281- /*
282- pyInputCodeMirror.setValue('x = 5');
283- pyTestInputCodeMirror.setValue('y = 10');
284- $(".problemDescClass").html('testing testing testing');
285- */
286-
287280 $ ( '#submitGradeBtn' ) . bind ( 'click' , function ( ) {
288281 $ ( '#submitGradeBtn' ) . html ( 'Now Grading ...' ) ;
289282 $ ( '#submitGradeBtn' ) . attr ( 'disabled' , true ) ;
0 commit comments