Skip to content

Commit de6aefb

Browse files
author
minjk-bl
committed
Fix Logic blocks to work fine on toggling (for Lab)
1 parent a5a3ff1 commit de6aefb

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

visualpython/js/board/Block.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,20 @@ define([
166166
let { elseFlag, finallyFlag } = this.state;
167167
if (taskId == 'lgCtrl_for' || taskId == 'lgCtrl_while') {
168168
page.appendLine('<div class="vp-block-button-group">');
169-
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'else', 'else', 'else ' + (elseFlag?'off':'on'));
169+
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'else', 'else', 'else ' + (elseFlag === true?'off':'on'));
170170
page.appendLine('</div>');
171171
}
172172
if (taskId == 'lgCtrl_if') {
173173
page.appendLine('<div class="vp-block-button-group">');
174174
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'elif', 'elif', '+ elif');
175-
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'else', 'else', 'else ' + (elseFlag?'off':'on'));
175+
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'else', 'else', 'else ' + (elseFlag === true?'off':'on'));
176176
page.appendLine('</div>');
177177
}
178178
if (taskId == 'lgCtrl_try') {
179179
page.appendLine('<div class="vp-block-button-group">');
180180
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'except', 'except', '+ except');
181-
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'else', 'else', 'else ' + (elseFlag?'off':'on'));
182-
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'finally', 'finally', 'finally ' + (finallyFlag?'off':'on'));
181+
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'else', 'else', 'else ' + (elseFlag === true?'off':'on'));
182+
page.appendFormatLine('<div class="vp-block-button {0}" data-menu="{1}">{2}</div>', 'finally', 'finally', 'finally ' + (finallyFlag === true?'off':'on'));
183183
page.appendLine('</div>');
184184
}
185185
page.appendLine('</div>');

visualpython/js/board/BoardFrame.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,16 +1087,16 @@ define([
10871087
let groupedBlocks = block.getGroupedBlocks();
10881088
let elseBlock = groupedBlocks.filter(obj => (obj.id === 'lgCtrl_else' && obj.depth === block.depth));
10891089
let finallyBlock = groupedBlocks.find(obj => (obj.id === 'lgCtrl_finally' && obj.depth === block.depth));
1090-
block.state.elseFlag = elseBlock!=undefined?true:false;
1091-
block.state.finallyFlag = finallyBlock!=undefined?true:false;
1090+
block.state.elseFlag = (elseBlock!==undefined?true:false);
1091+
block.state.finallyFlag = finallyBlock!==undefined?true:false;
10921092
}
10931093
toggleElseBlock(block) {
10941094
const blockIdx = this.blockList.indexOf(block);
10951095
let groupedBlocks = block.getGroupedBlocks();
10961096
let position = blockIdx + groupedBlocks.length; // add position
10971097
// check if it has else block
10981098
let elseFlag = block.state.elseFlag;
1099-
if (!elseFlag) {
1099+
if (elseFlag === false) {
11001100
// if finally is available, change add position
11011101
if (block.state.finallyFlag) {
11021102
let finallyBlock = groupedBlocks.find(obj => (obj.id === 'lgCtrl_finally' && obj.depth === block.depth));
@@ -1108,13 +1108,13 @@ define([
11081108
isGroup: false,
11091109
depth: block.depth
11101110
}
1111+
block.state.elseFlag = true;
11111112
this.prop.parent.createPopup([{
11121113
blockType: 'block',
11131114
menuId: 'lgCtrl_else',
11141115
menuState: { blockState: blockState },
11151116
position: position
11161117
}]);
1117-
block.state.elseFlag = true;
11181118
setTimeout(function() {
11191119
block.focusItem();
11201120
}, 100);
@@ -1138,19 +1138,19 @@ define([
11381138

11391139
// check if it has finally block
11401140
let finallyFlag = block.state.finallyFlag;
1141-
if (!finallyFlag) {
1141+
if (finallyFlag === false) {
11421142
// add finally
11431143
let blockState = {
11441144
isGroup: false,
11451145
depth: block.depth
11461146
}
1147+
block.state.finallyFlag = true;
11471148
this.prop.parent.createPopup([{
11481149
blockType: 'block',
11491150
menuId: 'lgCtrl_finally',
11501151
menuState: { blockState: blockState },
11511152
position: position
11521153
}]);
1153-
block.state.finallyFlag = true;
11541154
setTimeout(function() {
11551155
block.focusItem();
11561156
}, 100);
@@ -1172,7 +1172,7 @@ define([
11721172
let groupedBlocks = block.getGroupedBlocks();
11731173
let position = blockIdx + groupedBlocks.length; // add position
11741174
// if else is available, change add position
1175-
if (block.state.elseFlag) {
1175+
if (block.state.elseFlag === true) {
11761176
let elseBlock = groupedBlocks.find(obj => (obj.id === 'lgCtrl_else' && obj.depth === block.depth));
11771177
let elsePosition = this.blockList.indexOf(elseBlock);
11781178
position = elsePosition;
@@ -1198,13 +1198,13 @@ define([
11981198
let groupedBlocks = block.getGroupedBlocks();
11991199
let position = blockIdx + groupedBlocks.length; // add position
12001200
// if finally is available, change add position
1201-
if (block.state.finallyFlag) {
1201+
if (block.state.finallyFlag === true) {
12021202
let finallyBlock = groupedBlocks.find(obj => (obj.id === 'lgCtrl_finally' && obj.depth === block.depth));
12031203
let finallyPosition = this.blockList.indexOf(finallyBlock);
12041204
position = finallyPosition;
12051205
}
12061206
// if else is available, change add position
1207-
if (block.state.elseFlag) {
1207+
if (block.state.elseFlag === true) {
12081208
let elseBlock = groupedBlocks.find(obj => (obj.id === 'lgCtrl_else' && obj.depth === block.depth));
12091209
let elsePosition = this.blockList.indexOf(elseBlock);
12101210
position = elsePosition;

0 commit comments

Comments
 (0)