@@ -101,52 +101,25 @@ angular.module('frontend-app')
101101 fn ( ) ;
102102 }
103103 }
104+
104105 $scope . $on ( 'run-when-saved' , function ( evt , fn ) {
105106 runWhenSaved ( fn ) ;
106107 } ) ;
107- self . activateResize = function ( ) {
108+
109+ self . onResize = function ( ) {
108110 settings . settings . force_narrow = ! ( settings . settings . force_narrow ) ;
109111 settings . save ( ) ;
110112 } ;
111- // Resize on window size change
112- function onResize ( ) {
113- var narrow = ( settings . settings . force_narrow || $window . innerWidth < 992 ) ;
114- var min_height = 500 , margin_bottom = 30 ;
115- var editor_elem = $window . document . querySelector ( "#editor > .CodeMirror" ) ;
116- var console_elem = $window . document . querySelector ( "#console > .CodeMirror" ) ;
117- // Run only when DOM is ready.
118- if ( editor_elem && console_elem ) {
119- var target_height = Math . max ( $window . innerHeight - editor_elem . getBoundingClientRect ( ) . top - margin_bottom , min_height ) ;
120- var file_control_height = $window . document . querySelector ( '#current-file-controls' ) . offsetHeight ;
121- var console_input_height = $window . document . querySelector ( '#console-input' ) . offsetHeight ;
122- if ( editor_elem )
123- editor_elem . style . height = sprintf ( "%fpx" ,
124- ( narrow ? target_height * 0.7 : target_height ) - file_control_height ) ;
125- if ( console_elem )
126- console_elem . style . height = sprintf ( "%fpx" ,
127- ( narrow ? ( target_height * 0.3 - file_control_height ) : target_height ) - console_input_height ) ;
128- if ( self . editor )
129- self . editor . refresh ( ) ;
130- if ( self . consoleEditor )
131- self . consoleEditor . refresh ( ) ;
132- // Force the font size at any rate (and font name)
133- _ . each ( $window . document . querySelectorAll ( '.CodeMirror' ) ,
134- function ( elem ) {
135- elem . style [ 'font-family' ] = sprintf ( "%s, monospace" , settings . settings . font ) ;
136- elem . style [ 'font-size' ] = sprintf ( "%dpt" , parseInt ( settings . settings . font_size ) ) ;
137- } ) ;
138- }
139- }
140- $scope . $on ( 'window-resized' , onResize ) ;
113+
141114 // Scope helper function follow.
142115 self . consoleLoad = function ( console_cm ) {
143116 self . consoleEditor = console_cm ;
144117 self . consoleEditor . on ( "change" , function ( ) {
145118 var scr = self . consoleEditor . getScrollInfo ( ) ;
146119 self . consoleEditor . scrollTo ( scr . left , scr . height ) ;
147120 } ) ;
148- $timeout ( onResize , 0 ) ;
149121 } ;
122+
150123 self . editorLoad = function ( editor ) {
151124 self . editor = editor ;
152125 if ( self . ext === "c" || self . ext === "h" ) {
@@ -248,51 +221,69 @@ angular.module('frontend-app')
248221 self . editor . on ( "cursorActivity" , updateColNums ) ;
249222 self . editor . on ( "focus" , updateColNums ) ;
250223 self . editor . on ( "blur" , updateColNums ) ;
251- $timeout ( onResize , 0 ) ;
252224 } ;
225+
253226 function betterTab ( ) {
254227 if ( self . editor . somethingSelected ( ) ) {
255228 self . editor . indentSelection ( "add" ) ;
256229 } else {
257230 self . editor . replaceSelection ( Array ( self . editor . getOption ( "indentUnit" ) + 1 ) . join ( " " ) , "end" , "+input" ) ;
258231 }
259232 }
233+
260234 function negTab ( ) {
261235 if ( self . editor . somethingSelected ( ) ) {
262236 self . editor . indentSelection ( "subtract" ) ;
263237 }
264238 }
239+
265240 function toggleEditorFullscreen ( evt ) {
266241 evt . preventDefault ( ) ;
267242 self . consoleEditor . setOption ( 'fullScreen' , false ) ;
268243 self . editor . focus ( ) ;
269244 self . editor . setOption ( 'fullScreen' , ! self . editor . getOption ( 'fullScreen' ) ) ;
270245 }
246+
271247 function toggleConsoleFullscreen ( evt ) {
272248 evt . preventDefault ( ) ;
273249 self . editor . setOption ( 'fullScreen' , false ) ;
274250 self . consoleEditor . focus ( ) ;
275251 self . consoleEditor . setOption ( 'fullScreen' , ! self . consoleEditor . getOption ( 'fullScreen' ) ) ;
276252 }
253+
277254 function quitFullscreen ( evt ) {
278255 evt . preventDefault ( ) ;
279256 self . editor . setOption ( 'fullScreen' , false ) ;
280257 self . consoleEditor . setOption ( 'fullScreen' , false ) ;
281258 }
259+
282260 function increaseFontSize ( evt ) {
283261 evt . preventDefault ( ) ;
284- settings . settings . font_size = Math . min ( settings . settings . font_size + 2 , 100 ) ;
262+ settings . settings . font_size = Math . min ( settings . settings . font_size + 1 , 50 ) ;
285263 settings . save ( ) ;
286264 }
265+
287266 function decreaseFontSize ( evt ) {
288267 evt . preventDefault ( ) ;
289- settings . settings . font_size = Math . max ( settings . settings . font_size - 2 , 2 ) ;
268+ settings . settings . font_size = Math . max ( settings . settings . font_size - 1 , 1 ) ;
290269 settings . save ( ) ;
291270 }
271+
292272 self . refreshSettings = function ( ) {
293273 // var theme = settings.settings.theme_style === "light" ? "3024-day" : "3024-night";
294274 var theme = settings . settings . theme_style === "light" ? "default" : "3024-night" ;
295275 self . editorReadOnly = ! self . ready || self . isBinaryFile || self . fileReadOnly ;
276+
277+ var extraKeys = {
278+ "Ctrl-Space" : "autocomplete" ,
279+ "Ctrl-I" : self . indentAll ,
280+ // capture save shortcuts and ignore in the editor
281+ "Ctrl-S" : function ( ) { } ,
282+ "Cmd-S" : function ( ) { } ,
283+ "Tab" : betterTab ,
284+ "Shift-Tab" : negTab ,
285+ } ;
286+
296287 self . editorOptions = {
297288 scrollbarStyle : "overlay" ,
298289 autofocus : true ,
@@ -306,26 +297,19 @@ angular.module('frontend-app')
306297 onLoad : self . editorLoad ,
307298 matchBrackets : true ,
308299 rulers : [ 80 ] ,
309- extraKeys : {
310- "Ctrl-Space" : "autocomplete" ,
311- "Ctrl-I" : self . indentAll ,
312- // capture save shortcuts and ignore in the editor
313- "Ctrl-S" : function ( ) { } ,
314- "Cmd-S" : function ( ) { } ,
315- "Tab" : betterTab ,
316- "Shift-Tab" : negTab ,
317- }
300+ extraKeys : extraKeys
318301 } ;
302+
319303 self . consoleOptions = {
320304 scrollbarStyle : "overlay" ,
321305 lineWrapping : true ,
322306 readOnly : true ,
323307 mode : "text/plain" ,
324308 theme : theme ,
325309 onLoad : self . consoleLoad ,
326- extraKeys : {
327- } ,
310+ extraKeys : extraKeys
328311 } ;
312+
329313 var main_hotkeys = [ {
330314 combo : 'ctrl+d' ,
331315 description : 'Sends EOF' ,
@@ -368,6 +352,7 @@ angular.module('frontend-app')
368352 allowIn : [ 'INPUT' , 'SELECT' , 'TEXTAREA' ] ,
369353 callback : quitFullscreen
370354 } ] ;
355+
371356 var vim_disabled_hotkeys = [ {
372357 combo : 'ctrl+r' ,
373358 description : "Runs the program" ,
@@ -420,17 +405,25 @@ angular.module('frontend-app')
420405 for ( var key in self . editorOptions ) {
421406 self . editor . setOption ( key , self . editorOptions [ key ] ) ;
422407 }
408+ $ ( "#editor .CodeMirror *" ) . css ( {
409+ fontFamily : sprintf ( "%s, monospace" , settings . settings . font ) ,
410+ fontSize : sprintf ( "%dpt" , parseInt ( settings . settings . font_size ) )
411+ } ) ;
423412 self . editor . addKeyMap ( { 'Tab' : betterTab } ) ;
424413 self . editor . refresh ( ) ;
425414 }
426415 if ( self . consoleEditor ) {
427416 for ( var cKey in self . consoleOptions ) {
428417 self . consoleEditor . setOption ( cKey , self . consoleOptions [ cKey ] ) ;
429418 }
419+ $ ( "#console .CodeMirror *" ) . css ( {
420+ fontFamily : sprintf ( "%s, monospace" , settings . settings . font ) ,
421+ fontSize : sprintf ( "%dpt" , parseInt ( settings . settings . font_size ) )
422+ } ) ;
430423 self . consoleEditor . refresh ( ) ;
431424 }
432- onResize ( ) ;
433425 } ;
426+
434427 self . renameFile = function ( ) {
435428 renameModal ( self . project , self . question , self . folder , self . file , function ( newName ) {
436429 var path = newName . split ( "/" ) ;
@@ -441,7 +434,8 @@ angular.module('frontend-app')
441434 file :escape ( path . length > 2 ?path [ 2 ] :path [ 1 ] ) } ) ;
442435 } ) ;
443436 } ;
444- self . copyFile = function ( ) {
437+
438+ self . copyFile = function ( ) {
445439 copyModal ( self . project , self . question , self . folder , self . file , function ( newName ) {
446440 var path = newName . split ( "/" ) ;
447441 $scope . $parent . editView . refresh ( ) ;
@@ -451,6 +445,7 @@ angular.module('frontend-app')
451445 file :escape ( path . length > 2 ?path [ 2 ] :path [ 1 ] ) } ) ;
452446 } ) ;
453447 } ;
448+
454449 self . deleteFile = function ( ) {
455450 confirmModal ( "Delete File" , "Are you sure you want to delete '" + self . file + "'?" )
456451 . then ( function ( ) {
@@ -633,7 +628,7 @@ angular.module('frontend-app')
633628 } ;
634629
635630 // Initialization code goes here.
636- var settings_key = settings . addWatcher ( function ( ) { self . refreshSettings ( ) ; } , true ) ;
631+ var settings_key = settings . addWatcher ( self . refreshSettings , true ) ;
637632 $scope . $on ( "$destroy" , function ( ) {
638633 if ( self . timeout && self . ready ) {
639634 $timeout . cancel ( self . timeout ) ;
0 commit comments