@@ -36,11 +36,8 @@ var isExecutingCode = false; // nasty, nasty global
3636var appMode = 'edit' ; // 'edit' or 'display'. also support
3737 // 'visualize' for backward compatibility (same as 'display')
3838
39- var pyInputCodeMirror ; // CodeMirror object that contains the input code
4039var pyInputAceEditor ; // Ace editor object that contains the input code
4140
42- var useCodeMirror = false ; // true -> use CodeMirror, false -> use Ace
43-
4441
4542var dmp = new diff_match_patch ( ) ;
4643var curCode = '' ;
@@ -49,7 +46,7 @@ var deltaObj = undefined;
4946function initDeltaObj ( ) {
5047 // make sure the editor already exists
5148 // (editor doesn't exist when you're, say, doing an iframe embed)
52- if ( ! pyInputAceEditor && ! pyInputCodeMirror ) {
49+ if ( ! pyInputAceEditor ) {
5350 return ;
5451 }
5552
@@ -175,22 +172,12 @@ function supports_html5_storage() {
175172
176173// abstraction so that we can use either CodeMirror or Ace as our code editor
177174function pyInputGetValue ( ) {
178- if ( useCodeMirror ) {
179- return pyInputCodeMirror . getValue ( ) ;
180- }
181- else {
182- return pyInputAceEditor . getValue ( ) ;
183- }
175+ return pyInputAceEditor . getValue ( ) ;
184176}
185177
186178function pyInputSetValue ( dat ) {
187- if ( useCodeMirror ) {
188- pyInputCodeMirror . setValue ( dat . rtrim ( ) /* kill trailing spaces */ ) ;
189- }
190- else {
191- pyInputAceEditor . setValue ( dat . rtrim ( ) /* kill trailing spaces */ ,
192- - 1 /* do NOT select after setting text */ ) ;
193- }
179+ pyInputAceEditor . setValue ( dat . rtrim ( ) /* kill trailing spaces */ ,
180+ - 1 /* do NOT select after setting text */ ) ;
194181
195182 $ ( '#urlOutput,#embedCodeOutput' ) . val ( '' ) ;
196183
@@ -201,24 +188,12 @@ function pyInputSetValue(dat) {
201188}
202189
203190
204- var codeMirrorScroller = '#codeInputPane .CodeMirror-scroll' ;
205-
206191function pyInputGetScrollTop ( ) {
207- if ( useCodeMirror ) {
208- return $ ( codeMirrorScroller ) . scrollTop ( ) ;
209- }
210- else {
211- return pyInputAceEditor . getSession ( ) . getScrollTop ( ) ;
212- }
192+ return pyInputAceEditor . getSession ( ) . getScrollTop ( ) ;
213193}
214194
215195function pyInputSetScrollTop ( st ) {
216- if ( useCodeMirror ) {
217- $ ( codeMirrorScroller ) . scrollTop ( st ) ;
218- }
219- else {
220- pyInputAceEditor . getSession ( ) . setScrollTop ( st ) ;
221- }
196+ pyInputAceEditor . getSession ( ) . setScrollTop ( st ) ;
222197}
223198
224199
@@ -241,79 +216,33 @@ function genericOptFrontendReady() {
241216 } ) ;
242217
243218
244- if ( useCodeMirror ) {
245- pyInputCodeMirror = CodeMirror ( document . getElementById ( 'codeInputPane' ) , {
246- mode : 'python' ,
247- lineNumbers : true ,
248- tabSize : 4 ,
249- indentUnit : 4 ,
250- // convert tab into four spaces:
251- extraKeys : { Tab : function ( cm ) { cm . replaceSelection ( " " , "end" ) ; } }
252- } ) ;
253-
254- pyInputCodeMirror . setSize ( null , '420px' ) ;
255- }
256- else {
257- initAceEditor ( 420 ) ;
258- }
219+ initAceEditor ( 420 ) ;
259220
260221
261- if ( useCodeMirror ) {
262- // for shared sessions
263- pyInputCodeMirror . on ( "change" , function ( cm , change ) {
264- // only trigger when the user explicitly typed something
265- if ( change . origin != 'setValue' ) {
266- //if (TogetherJS.running) {
267- // TogetherJS.send({type: "codemirror-edit"});
268- //}
269- }
270- } ) ;
271- }
272- else {
273- pyInputAceEditor . getSession ( ) . on ( "change" , function ( e ) {
274- // unfortunately, Ace doesn't detect whether a change was caused
275- // by a setValue call
276- //if (TogetherJS.running) {
277- // TogetherJS.send({type: "codemirror-edit"});
278- //}
279- } ) ;
280- }
222+ pyInputAceEditor . getSession ( ) . on ( "change" , function ( e ) {
223+ // unfortunately, Ace doesn't detect whether a change was caused
224+ // by a setValue call
225+ //if (TogetherJS.running) {
226+ // TogetherJS.send({type: "codemirror-edit"});
227+ //}
228+ } ) ;
281229
282230
283- if ( useCodeMirror ) {
284- $ ( codeMirrorScroller ) . scroll ( function ( e ) {
285- /*
286- if (TogetherJS.running) {
287- var elt = $(this);
288- $.doTimeout('codeInputScroll', 100, function() { // debounce
289- // note that this will send a signal back and forth both ways
290- // (there's no easy way to prevent this), but it shouldn't keep
291- // bouncing back and forth indefinitely since no the second signal
292- // causes no additional scrolling
293- TogetherJS.send({type: "codeInputScroll",
294- scrollTop: elt.scrollTop()});
295- });
296- }
297- */
298- } ) ;
299- }
300- else {
301- // don't sync for Ace since I can't get it working properly yet
302- /*
303- pyInputAceEditor.getSession().on('changeScrollTop', function() {
304- if (TogetherJS.running) {
305- $.doTimeout('codeInputScroll', 100, function() { // debounce
306- // note that this will send a signal back and forth both ways
307- // (there's no easy way to prevent this), but it shouldn't keep
308- // bouncing back and forth indefinitely since no the second signal
309- // causes no additional scrolling
310- TogetherJS.send({type: "codeInputScroll",
311- scrollTop: pyInputGetScrollTop()});
312- });
313- }
314- });
315- */
316- }
231+ // don't sync for Ace since I can't get it working properly yet
232+ /*
233+ pyInputAceEditor.getSession().on('changeScrollTop', function() {
234+ if (TogetherJS.running) {
235+ $.doTimeout('codeInputScroll', 100, function() { // debounce
236+ // note that this will send a signal back and forth both ways
237+ // (there's no easy way to prevent this), but it shouldn't keep
238+ // bouncing back and forth indefinitely since no the second signal
239+ // causes no additional scrolling
240+ TogetherJS.send({type: "codeInputScroll",
241+ scrollTop: pyInputGetScrollTop()});
242+ });
243+ }
244+ });
245+ */
317246
318247
319248 // first initialize options from HTML LocalStorage. very important
@@ -378,7 +307,7 @@ function genericOptFrontendReady() {
378307}
379308
380309
381- // sets globals such as rawInputLst, CodeMirror input box, and toggle options
310+ // sets globals such as rawInputLst, code input box, and toggle options
382311function parseQueryString ( ) {
383312 var queryStrOptions = getQueryStringOptions ( ) ;
384313 setToggleOptions ( queryStrOptions ) ;
@@ -620,27 +549,14 @@ function executeCodeWithRawInput(rawInputStr, curInstr) {
620549
621550function handleUncaughtExceptionFunc ( trace ) {
622551 if ( trace . length == 1 && trace [ 0 ] . line ) {
623- var errorLineNo = trace [ 0 ] . line - 1 ; /* CodeMirror lines are zero-indexed */
552+ var errorLineNo = trace [ 0 ] . line - 1 ; /* Ace lines are zero-indexed */
624553 if ( errorLineNo !== undefined && errorLineNo != NaN ) {
625554 // highlight the faulting line
626- if ( useCodeMirror ) {
627- pyInputCodeMirror . focus ( ) ;
628- pyInputCodeMirror . setCursor ( errorLineNo , 0 ) ;
629- pyInputCodeMirror . addLineClass ( errorLineNo , null , 'errorLine' ) ;
630-
631- function f ( ) {
632- pyInputCodeMirror . removeLineClass ( errorLineNo , null , 'errorLine' ) ; // reset line back to normal
633- pyInputCodeMirror . off ( 'change' , f ) ;
634- }
635- pyInputCodeMirror . on ( 'change' , f ) ;
636- }
637- else {
638- var s = pyInputAceEditor . getSession ( ) ;
639- s . setAnnotations ( [ { row : errorLineNo ,
640- type : 'error' ,
641- text : trace [ 0 ] . exception_msg } ] ) ;
642- pyInputAceEditor . gotoLine ( errorLineNo + 1 /* one-indexed */ ) ;
643- }
555+ var s = pyInputAceEditor . getSession ( ) ;
556+ s . setAnnotations ( [ { row : errorLineNo ,
557+ type : 'error' ,
558+ text : trace [ 0 ] . exception_msg } ] ) ;
559+ pyInputAceEditor . gotoLine ( errorLineNo + 1 /* one-indexed */ ) ;
644560 }
645561 }
646562}
0 commit comments