feat: Add 'reason' field to move event (#6996)

* feat: Add 'reason' field to move event

There are many types of move.  This addition allows one to detect what the reason for each move is.

* Clang formatting.

And unsaved editor tabs.

* Change reason string to array.
This commit is contained in:
Neil Fraser
2023-04-26 00:22:10 +02:00
committed by GitHub
parent 139bc299a0
commit 64aa3e7df4
12 changed files with 71 additions and 16 deletions

View File

@@ -2130,13 +2130,15 @@ export class Block implements IASTNodeLocation, IDeletable {
*
* @param dx Horizontal offset, in workspace units.
* @param dy Vertical offset, in workspace units.
* @param reason Why is this move happening? 'drag', 'bump', 'snap', ...
*/
moveBy(dx: number, dy: number) {
moveBy(dx: number, dy: number, reason?: string[]) {
if (this.parentBlock_) {
throw Error('Block has parent.');
throw Error('Block has parent');
}
const event =
new (eventUtils.get(eventUtils.BLOCK_MOVE))(this) as BlockMove;
reason && event.setReason(reason);
this.xy_.translate(dx, dy);
event.recordNew();
eventUtils.fire(event);