@@ -65,6 +65,7 @@ var appMode = 'edit'; // 'edit' or 'display'. also support
6565 // 'visualize' for backward compatibility (same as 'display')
6666
6767var pyInputCodeMirror ; // CodeMirror object that contains the input text
68+ var pyInputAceEditor ; // Ace editor object that contains the input text
6869
6970
7071// BEGIN - shared session stuff
@@ -99,7 +100,7 @@ var executeCodeSignalFromRemote = false;
99100var togetherjsSyncRequested = false ;
100101var pendingCodeOutputScrollTop = null ;
101102
102- var codeMirrorScroller = '#codeInputPane .CodeMirror-scroll' ;
103+ var pyInputScroller = '#codeInputPane .CodeMirror-scroll' ;
103104
104105TogetherJSConfig_ignoreForms = [ '.togetherjsIgnore' ] ; // do NOT sync these elements
105106
@@ -120,7 +121,7 @@ function syncAppState(appState) {
120121 // up because the initial states of the two forms aren't equal.
121122 var orig = TogetherJS . config . get ( 'ignoreForms' ) ;
122123 TogetherJS . config ( 'ignoreForms' , true ) ;
123- setCodeMirrorVal ( appState . code ) ;
124+ pyInputSetValue ( appState . code ) ;
124125 TogetherJS . config ( 'ignoreForms' , orig ) ;
125126
126127 if ( appState . rawInputLst ) {
@@ -264,10 +265,10 @@ function initTogetherJS() {
264265 updateAppDisplay ( msg . appMode ) ;
265266
266267 if ( appMode == 'edit' && msg . codeInputScrollTop !== undefined &&
267- $ ( codeMirrorScroller ) . scrollTop ( ) != msg . codeInputScrollTop ) {
268+ $ ( pyInputScroller ) . scrollTop ( ) != msg . codeInputScrollTop ) {
268269 // hack: give it a bit of time to settle first ...
269270 $ . doTimeout ( 'pyInputCodeMirrorInit' , 200 , function ( ) {
270- $ ( codeMirrorScroller ) . scrollTop ( msg . codeInputScrollTop ) ;
271+ $ ( pyInputScroller ) . scrollTop ( msg . codeInputScrollTop ) ;
271272 } ) ;
272273 }
273274 }
@@ -296,7 +297,7 @@ function initTogetherJS() {
296297 if ( TogetherJS . running ) {
297298 TogetherJS . send ( { type : "myAppState" ,
298299 myAppState : getAppState ( ) ,
299- codeInputScrollTop : $ ( '#codeInputPane .CodeMirror-scroll' ) . scrollTop ( ) ,
300+ codeInputScrollTop : $ ( pyInputScroller ) . scrollTop ( ) ,
300301 pyCodeOutputDivScrollTop : myVisualizer ?
301302 myVisualizer . domRoot . find ( '#pyCodeOutputDiv' ) . scrollTop ( ) :
302303 undefined } ) ;
@@ -356,7 +357,7 @@ function initTogetherJS() {
356357 // value. this is hacky; ideally we have a callback function for
357358 // when setValue() completes.
358359 $ . doTimeout ( 'pyInputCodeMirrorInit' , 200 , function ( ) {
359- $ ( codeMirrorScroller ) . scrollTop ( msg . codeInputScrollTop ) ;
360+ $ ( pyInputScroller ) . scrollTop ( msg . codeInputScrollTop ) ;
360361 } ) ;
361362 }
362363 } ) ;
@@ -365,7 +366,7 @@ function initTogetherJS() {
365366 // do NOT use a msg.sameUrl guard since that will miss some signals
366367 // due to our funky URLs
367368
368- $ ( codeMirrorScroller ) . scrollTop ( msg . scrollTop ) ;
369+ $ ( pyInputScroller ) . scrollTop ( msg . scrollTop ) ;
369370 } ) ;
370371
371372 TogetherJS . hub . on ( "pyCodeOutputDivScroll" , function ( msg ) {
@@ -485,17 +486,6 @@ var try_hook = function(hook_name, args) {
485486 return [ false ] ; // just a stub
486487}
487488
488- function setCodeMirrorVal ( dat ) {
489- pyInputCodeMirror . setValue ( dat . rtrim ( ) /* kill trailing spaces */ ) ;
490- $ ( '#urlOutput,#embedCodeOutput' ) . val ( '' ) ;
491-
492- clearFrontendError ( ) ;
493-
494- // also scroll to top to make the UI more usable on smaller monitors
495- $ ( document ) . scrollTop ( 0 ) ;
496- }
497-
498-
499489var myVisualizer = null ; // singleton ExecutionVisualizer instance
500490
501491var rawInputLst = [ ] ; // a list of strings inputted by the user in response to raw_input or mouse_input events
@@ -533,6 +523,22 @@ function supports_html5_storage() {
533523 }
534524}
535525
526+ // abstraction so that we can swap out CodeMirror or Ace
527+ function pyInputGetValue ( ) {
528+ return pyInputCodeMirror . getValue ( ) ;
529+ }
530+
531+ function pyInputSetValue ( val ) {
532+ pyInputCodeMirror . setValue ( dat . rtrim ( ) /* kill trailing spaces */ ) ;
533+ $ ( '#urlOutput,#embedCodeOutput' ) . val ( '' ) ;
534+
535+ clearFrontendError ( ) ;
536+
537+ // also scroll to top to make the UI more usable on smaller monitors
538+ $ ( document ) . scrollTop ( 0 ) ;
539+ }
540+
541+
536542// run at the END so that everything else can be initialized first
537543function genericOptFrontendReady ( ) {
538544 initTogetherJS ( ) ; // initialize early
@@ -556,7 +562,7 @@ function genericOptFrontendReady() {
556562 if ( TogetherJS . running && ! isExecutingCode ) {
557563 TogetherJS . send ( { type : "hashchange" ,
558564 appMode : appMode ,
559- codeInputScrollTop : $ ( codeMirrorScroller ) . scrollTop ( ) ,
565+ codeInputScrollTop : $ ( pyInputScroller ) . scrollTop ( ) ,
560566 myAppState : getAppState ( ) } ) ;
561567 }
562568 } ) ;
@@ -574,6 +580,19 @@ function genericOptFrontendReady() {
574580 pyInputCodeMirror . setSize ( null , '420px' ) ;
575581
576582
583+ pyInputAceEditor = ace . edit ( 'codeInputPaneAce' ) ;
584+ var s = pyInputAceEditor . getSession ( ) ;
585+ s . setMode ( "ace/mode/python" ) ;
586+ // tab -> 4 spaces
587+ s . setTabSize ( 4 ) ;
588+ s . setUseSoftTabs ( true ) ;
589+ // disable extraneous indicators:
590+ s . setFoldStyle ( 'manual' ) ; // no code folding indicators
591+ pyInputAceEditor . setHighlightActiveLine ( false ) ;
592+ pyInputAceEditor . setShowPrintMargin ( false ) ;
593+ pyInputAceEditor . setBehavioursEnabled ( false ) ;
594+
595+
577596 // for shared sessions
578597 pyInputCodeMirror . on ( "change" , function ( cm , change ) {
579598 // only trigger when the user explicitly typed something
@@ -584,7 +603,7 @@ function genericOptFrontendReady() {
584603 }
585604 } ) ;
586605
587- $ ( '#codeInputPane .CodeMirror-scroll' ) . scroll ( function ( e ) {
606+ $ ( pyInputScroller ) . scroll ( function ( e ) {
588607 if ( TogetherJS . running ) {
589608 var elt = $ ( this ) ;
590609 // debounce
@@ -724,7 +743,7 @@ function parseQueryString() {
724743 var queryStrOptions = getQueryStringOptions ( ) ;
725744 setToggleOptions ( queryStrOptions ) ;
726745 if ( queryStrOptions . preseededCode ) {
727- setCodeMirrorVal ( queryStrOptions . preseededCode ) ;
746+ pyInputSetValue ( queryStrOptions . preseededCode ) ;
728747 }
729748 if ( queryStrOptions . rawInputLst ) {
730749 rawInputLst = queryStrOptions . rawInputLst ; // global
0 commit comments