@@ -168,25 +168,29 @@ document.addEventListener("DOMContentLoaded", () => {
168168 return roundedtime + '\xa0' + prefices [ i ] + "s"
169169 }
170170
171- function updateLocalCellOutput ( cellNode , mime , output , errormessage , runtime ) {
172- cellNode . classList . remove ( "running" )
173- cellNode . querySelector ( "runarea>span" ) . innerText = prettytime ( runtime )
171+ function updateLocalCellOutput ( cellNode , msg ) {
172+ if ( msg . running ) {
173+ cellNode . classList . add ( "running" )
174+ } else {
175+ cellNode . classList . remove ( "running" )
176+ }
177+ cellNode . querySelector ( "runarea>span" ) . innerText = prettytime ( msg . runtime )
174178
175179 const outputNode = cellNode . querySelector ( "celloutput" )
176180
177181 oldHeight = outputNode . scrollHeight
178182
179- if ( errormessage ) {
183+ if ( msg . errormessage ) {
180184 outputNode . innerHTML = "<pre><code></code></pre>"
181- outputNode . querySelector ( "code" ) . innerHTML = rewrittenError ( errormessage )
185+ outputNode . querySelector ( "code" ) . innerHTML = rewrittenError ( msg . errormessage )
182186 cellNode . classList . add ( "error" )
183187 } else {
184188 cellNode . classList . remove ( "error" )
185- if ( mime == "text/html" || mime == "image/svg+xml" ) {
189+ if ( msg . mime == "text/html" || msg . mime == "image/svg+xml" ) {
186190
187- // if(outputNode.innerHTML != output){
191+ // if(outputNode.innerHTML != msg. output){
188192 // }
189- outputNode . innerHTML = output
193+ outputNode . innerHTML = msg . output
190194
191195 // from https://stackoverflow.com/a/26716182
192196 // to execute all scripts in the output html:
@@ -215,11 +219,11 @@ document.addEventListener("DOMContentLoaded", () => {
215219 MathJax . typeset ( )
216220 } else {
217221 outputNode . innerHTML = "<pre><code></code></pre>"
218- outputNode . querySelector ( "code" ) . innerText = output
222+ outputNode . querySelector ( "code" ) . innerText = msg . output
219223 }
220224 }
221- document . dispatchEvent ( new CustomEvent ( "celloutputchanged" , { detail : { cell : cellNode , mime : mime } } ) )
222- if ( output == null && errormessage == null ) {
225+ document . dispatchEvent ( new CustomEvent ( "celloutputchanged" , { detail : { cell : cellNode , mime : msg . mime } } ) )
226+ if ( msg . output == null && msg . errormessage == null ) {
223227 cellNode . classList . add ( "output-notinsync" )
224228 } else {
225229 cellNode . classList . remove ( "output-notinsync" )
@@ -299,7 +303,7 @@ document.addEventListener("DOMContentLoaded", () => {
299303 newFolded = false
300304 } else if ( window . getSelection ( ) . isCollapsed ) {
301305 // Do not fold if the click event was fired because the user selects text in the output.
302- if ( e . target . tagName != "A" && e . target . tagName != "INPUT" ) {
306+ if ( e . target . tagName != "A" && e . target . tagName != "INPUT" && e . target . tagName != "SELECT" ) {
303307 // Do not fold if a link was clicked.
304308 newFolded = ! newFolded
305309 }
@@ -376,8 +380,8 @@ document.addEventListener("DOMContentLoaded", () => {
376380
377381 /* REQUEST FUNCTIONS FOR REMOTE CHANGES */
378382
379- window . allCellsCompleted = true
380- window . allCellsCompletedPromise = new Promise ( r => r ( ) ) // resolved
383+ window . allCellsCompleted = true // will be set to false soon
384+ window . allCellsCompletedPromise = null
381385
382386 function refreshAllCompletionPromise ( ) {
383387 if ( allCellsCompleted ) {
@@ -389,6 +393,7 @@ document.addEventListener("DOMContentLoaded", () => {
389393 }
390394
391395 window . refreshAllCompletionPromise = refreshAllCompletionPromise
396+ refreshAllCompletionPromise ( )
392397
393398 function requestChangeRemoteCell ( uuid , createPromise = false ) {
394399 refreshAllCompletionPromise ( )
@@ -398,21 +403,25 @@ document.addEventListener("DOMContentLoaded", () => {
398403 return client . send ( "changecell" , { code : newCode } , uuid , createPromise )
399404 }
400405
401- function requestRunAllRemoteCells ( ) {
406+ function requestRunAllRemoteCells ( setInputs = true ) {
407+ if ( ! window . allCellsCompleted ) {
408+ return
409+ }
402410 refreshAllCompletionPromise ( )
403411 const promises = [ ]
404412
405413 for ( var uuid in window . localCells ) {
406414 const cellNode = window . localCells [ uuid ]
407415 cellNode . classList . add ( "running" )
408- promises . push (
409- client . sendreceive ( "setinput" , {
410- code : window . codeMirrors [ uuid ] . getValue ( )
411- } , uuid ) . then ( u => {
412- updateLocalCellInput ( true , cellNode , u . message . code , u . message . folded )
413- } )
414- )
415-
416+ if ( setInputs ) {
417+ promises . push (
418+ client . sendreceive ( "setinput" , {
419+ code : window . codeMirrors [ uuid ] . getValue ( )
420+ } , uuid ) . then ( u => {
421+ updateLocalCellInput ( true , cellNode , u . message . code , u . message . folded )
422+ } )
423+ )
424+ }
416425 }
417426 Promise . all ( promises ) . then ( ( ) => {
418427 client . send ( "runall" , { } )
@@ -452,7 +461,7 @@ document.addEventListener("DOMContentLoaded", () => {
452461
453462 switch ( update . type ) {
454463 case "cell_output" :
455- updateLocalCellOutput ( window . localCells [ update . cellID ] , message . mime , message . output , message . errormessage , message . runtime )
464+ updateLocalCellOutput ( window . localCells [ update . cellID ] , message )
456465 break
457466 case "cell_running" :
458467 // TODO: catch exception
@@ -499,6 +508,7 @@ document.addEventListener("DOMContentLoaded", () => {
499508 window . customPlutoListeners = { }
500509
501510 function onEstablishConnection ( ) {
511+ const runAll = client . plutoCONFIG [ "PLUTO_RUN_NOTEBOOK_ON_LOAD" ] == "true"
502512 // on socket success
503513 client . send ( "getallnotebooks" , { } )
504514
@@ -507,27 +517,35 @@ document.addEventListener("DOMContentLoaded", () => {
507517
508518 update . message . cells . forEach ( ( cell , index ) => {
509519 const cellNode = createLocalCell ( index , cell . uuid , "" , false )
520+ runAll && cellNode . classList . add ( "running" )
510521 promises . push (
511522 client . sendreceive ( "getinput" , { } , cell . uuid ) . then ( u => {
512523 updateLocalCellInput ( true , cellNode , u . message . code , u . message . folded )
513524 } )
514525 )
515526 promises . push (
516527 client . sendreceive ( "getoutput" , { } , cell . uuid ) . then ( u => {
517- const message = u . message
518- updateLocalCellOutput ( cellNode , message . mime , message . output , message . errormessage , message . runtime )
528+ updateLocalCellOutput ( cellNode , u . message )
519529 } )
520530 )
521531 } )
522532
523533 Promise . all ( promises ) . then ( ( ) => {
524- // We do a code completion request to trigger starting the workpsace
525- client . sendreceive ( "complete" , {
526- query : "nothinginparticular"
527- } ) . then ( ( ) => {
534+ function happy ( ) {
528535 document . body . classList . remove ( "loading" )
529536 console . info ( "Workspace initialized" )
530- } )
537+ }
538+ if ( runAll
539+ && ! document . querySelector ( "notebook>cell.running" )
540+ && document . querySelector ( "notebook>cell.output-notinsync" ) ) {
541+ requestRunAllRemoteCells ( false )
542+ window . allCellsCompletedPromise . then ( happy )
543+ } else {
544+ // We do a code completion request to trigger starting the workpsace
545+ client . sendreceive ( "complete" , {
546+ query : "nothinginparticular"
547+ } ) . then ( happy )
548+ }
531549 } )
532550 } ) . catch ( console . error )
533551
@@ -773,6 +791,14 @@ document.addEventListener("DOMContentLoaded", () => {
773791 e . preventDefault ( )
774792 }
775793 break
794+ case 82 : // r
795+ if ( e . ctrlKey ) {
796+ if ( notebookPath != "unknown" ) {
797+ document . location . href = "/open?path=" + encodeURIComponent ( notebookPath )
798+ e . preventDefault ( )
799+ }
800+ }
801+ break
776802 case 83 : // s
777803 if ( e . ctrlKey ) {
778804 filePickerCodeMirror . focus ( )
0 commit comments