Skip to content

Commit c6e4021

Browse files
author
minjk-bl
committed
Add default except block to try block, focus block after else/finally on and off
1 parent 3e7e067 commit c6e4021

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

js/MainFrame.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ define([
372372
if (OptionComponent) {
373373
let taskState = menuState.taskState;
374374
let blockState = menuState.blockState;
375+
let tmpState = menuState.tmpState;
375376
let state = {
376377
...taskState,
377378
config: menuConfig
@@ -386,9 +387,14 @@ define([
386387
parentBlock = newBlock; // set parent block of created block
387388
} else {
388389
if (prevBlock != null && !newBlock.isGroup) {
389-
newBlock.setDepth(prevBlock.getChildDepth());
390+
let newDepth = prevBlock.getChildDepth();
391+
if (tmpState && tmpState.relativeDepth) {
392+
newDepth = parentBlock.getChildDepth() + tmpState.relativeDepth;
393+
}
394+
newBlock.setDepth(newDepth);
390395
}
391396
}
397+
vpLog.display(VP_LOG_TYPE.DEVELOP, 'new block ' + position + ' with depth ' + newBlock.depth);
392398
prevBlock = newBlock;
393399
} else {
394400
// add to task list
@@ -485,10 +491,42 @@ define([
485491
}
486492
]
487493
break;
494+
case 'lgCtrl_try':
495+
childBlocks = [
496+
{
497+
menuId: 'lgCtrl_pass',
498+
menuState: {
499+
blockState: {
500+
isGroup: false
501+
}
502+
}
503+
},
504+
{
505+
menuId: 'lgCtrl_except',
506+
menuState: {
507+
blockState: {
508+
isGroup: false
509+
},
510+
tmpState: {
511+
relativeDepth: -1
512+
}
513+
}
514+
},
515+
{
516+
menuId: 'lgCtrl_pass',
517+
menuState: {
518+
blockState: {
519+
isGroup: false
520+
}
521+
}
522+
}
523+
524+
];
525+
break;
526+
break;
488527
case 'lgCtrl_for':
489528
case 'lgCtrl_while':
490529
case 'lgCtrl_if':
491-
case 'lgCtrl_try':
492530
case 'lgCtrl_elif':
493531
case 'lgCtrl_except':
494532
case 'lgCtrl_else':

js/board/BoardFrame.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ define([
768768
if (elseBlock.length > 0) {
769769
this.removeBlock(elseBlock[0]);
770770
}
771+
// focus it
772+
setTimeout(function() {
773+
block.focusItem();
774+
}, 100);
771775
}
772776
}
773777

@@ -800,6 +804,10 @@ define([
800804
if (finallyBlock) {
801805
this.removeBlock(finallyBlock);
802806
}
807+
// focus it
808+
setTimeout(function() {
809+
block.focusItem();
810+
}, 100);
803811
}
804812
}
805813

0 commit comments

Comments
 (0)