Skip to content

Commit 0469fa1

Browse files
authored
Merge pull request #2435 from entrylabs/issue/5181
Issue/5181
2 parents cb83e19 + 39f261d commit 0469fa1

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/playground/block_entry.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,6 @@ function getBlocks() {
18551855
},
18561856
},
18571857
],
1858-
isPrimitive: true,
18591858
events: {},
18601859
def: {
18611860
params: [null],

src/playground/board.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,15 +1499,18 @@ Entry.Board = class Board {
14991499
this.svgObjectBlockCount.countText = countText;
15001500
}
15011501

1502-
const nameWidth = Math.round(this.svgObjectTitle?.name?.getBoundingClientRect().width || 0);
1502+
const nameWidth =
1503+
Math.round(this.svgObjectTitle?.name?.getBoundingClientRect().width || 0) / this.scale;
15031504
const x = nameWidth + 8;
15041505
this.svgObjectBlockCount.countText.attr({
15051506
x: 44 + x + 8,
15061507
y: 26,
15071508
});
15081509
requestAnimationFrame(() => {
1510+
const rectWidth =
1511+
this.svgObjectBlockCount.countText.getBoundingClientRect().width / this.scale;
15091512
this.svgObjectBlockCount.rect.attr({
1510-
width: this.svgObjectBlockCount.countText.getBoundingClientRect().width + 16,
1513+
width: rectWidth + 16,
15111514
x: 44 + x,
15121515
y: 12,
15131516
});

src/playground/thread.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Entry.Thread = class Thread {
4040
if (codeView) {
4141
this.createView(codeView.board, mode);
4242
}
43+
this.resetEvent();
4344
return this;
4445
}
4546

@@ -78,11 +79,13 @@ Entry.Thread = class Thread {
7879
}
7980

8081
this._code.createThread(this._data.splice(this._data.indexOf(block), count), index);
82+
this.resetEvent();
8183
this.changeEvent.notify();
8284
}
8385

8486
cut(block) {
8587
const splicedData = this._data.splice(this._data.indexOf(block));
88+
this.resetEvent();
8689
this.changeEvent.notify();
8790
return splicedData;
8891
}
@@ -93,12 +96,14 @@ Entry.Thread = class Thread {
9396
newBlocks[i].setThread(this);
9497
}
9598
this._data.splice(...[index + 1, 0].concat(newBlocks));
99+
this.resetEvent();
96100
this.changeEvent.notify();
97101
}
98102

99103
insertToTop(newBlock) {
100104
newBlock.setThread(this);
101105
this._data.unshift.apply(this._data, [newBlock]);
106+
this.resetEvent();
102107
this.changeEvent.notify();
103108
}
104109

@@ -181,6 +186,7 @@ Entry.Thread = class Thread {
181186

182187
spliceBlock(block) {
183188
this._data.remove(block);
189+
this.resetEvent();
184190
this.changeEvent.notify();
185191
}
186192

@@ -330,4 +336,11 @@ Entry.Thread = class Thread {
330336
hasData() {
331337
return Boolean(this._data.length);
332338
}
339+
340+
resetEvent() {
341+
const block = this.getFirstBlock();
342+
if (block && this._event !== block?._schema?.event) {
343+
this._event = block?._schema?.event;
344+
}
345+
}
333346
};

src/playground/trashcan.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ Entry.FieldTrashcan = class FieldTrashcan {
6262
if (this.dragBlock instanceof Entry.BlockView) {
6363
const prevBlock = this.dragBlock.block.getPrevBlock();
6464
if (!prevBlock) {
65+
const script = this.dragBlock.block.getCode();
6566
Entry.do('destroyThread', this.dragBlock.block.thread, 'trashcan').isPass(
6667
true,
6768
true
6869
);
6970
Entry.Utils.playSound('entryDelete');
71+
script?.changeEvent?.notify();
7072
}
7173
} else if (this.dragBlock instanceof Entry.Comment) {
7274
Entry.do('removeComment', this.dragBlock).isPass(true, true);

0 commit comments

Comments
 (0)