@@ -228,6 +228,15 @@ async function store(state, emitter) {
228
228
} )
229
229
230
230
// CODE EXECUTION
231
+ emitter . on ( 'run-from-button' , ( onlySelected = false ) => {
232
+ if ( onlySelected ) {
233
+ runCodeSelection ( )
234
+ } else {
235
+ runCode ( )
236
+ }
237
+ } )
238
+
239
+
231
240
emitter . on ( 'run' , async ( onlySelected = false ) => {
232
241
log ( 'run' )
233
242
const openFile = state . openFiles . find ( f => f . id == state . editingFile )
@@ -1506,14 +1515,35 @@ async function store(state, emitter) {
1506
1515
emitter . emit ( 'render' )
1507
1516
}
1508
1517
1518
+ // Ensures that even if the RUN button is clicked multiple times
1519
+ // there's a 100ms delay between each execution to prevent double runs
1520
+ // and entering an unstable state because of getPrompt() calls
1521
+ let preventDoubleRun = false
1522
+ function timedReset ( ) {
1523
+ preventDoubleRun = true
1524
+ setTimeout ( ( ) => {
1525
+ preventDoubleRun = false
1526
+ } , 500 ) ;
1527
+
1528
+ }
1529
+
1530
+ function filterDoubleRun ( onlySelected = false ) {
1531
+ if ( preventDoubleRun ) return
1532
+ console . log ( '>>> RUN CODE ACTUAL <<<' )
1533
+ emitter . emit ( 'run' , onlySelected )
1534
+ timedReset ( )
1535
+ }
1536
+
1509
1537
function runCode ( ) {
1538
+ console . log ( '>>> RUN CODE REQUEST <<<' )
1510
1539
if ( canExecute ( { view : state . view , isConnected : state . isConnected } ) ) {
1511
- emitter . emit ( 'run' )
1540
+ filterDoubleRun ( )
1512
1541
}
1513
1542
}
1514
1543
function runCodeSelection ( ) {
1544
+ console . log ( '>>> RUN CODE REQUEST <<<' )
1515
1545
if ( canExecute ( { view : state . view , isConnected : state . isConnected } ) ) {
1516
- emitter . emit ( 'run' , true )
1546
+ filterDoubleRun ( true )
1517
1547
}
1518
1548
}
1519
1549
function stopCode ( ) {
0 commit comments