|
13 | 13 | * @author aschmiedt@google.com (Abby Schmiedt)
|
14 | 14 | */
|
15 | 15 |
|
| 16 | +import { FieldColour } from '@blockly/field-colour'; |
16 | 17 | import * as Blockly from 'blockly/core';
|
17 | 18 | import {ASTNode, Marker} from 'blockly/core';
|
18 | 19 |
|
@@ -424,15 +425,44 @@ export class LineCursor extends Marker {
|
424 | 425 | const oldNode = (this as any).curNode;
|
425 | 426 | (this as any).curNode = newNode;
|
426 | 427 | const drawer = (this as any).drawer;
|
| 428 | + if (!drawer) { |
| 429 | + console.error('could not find a drawer'); |
| 430 | + return; |
| 431 | + } |
| 432 | + |
| 433 | + const newNodeIsFieldColour = newNode?.getType() == ASTNode.types.FIELD && |
| 434 | + (newNode.getLocation() as Blockly.Field) instanceof FieldColour; |
| 435 | + const oldNodeIsFieldColour = oldNode?.getType() == ASTNode.types.FIELD && |
| 436 | + (oldNode.getLocation() as Blockly.Field) instanceof FieldColour |
| 437 | + |
| 438 | + |
427 | 439 | if (newNode?.getType() == ASTNode.types.BLOCK) {
|
428 |
| - if (drawer) { |
429 |
| - drawer.hide(); |
430 |
| - } |
| 440 | + drawer.hide(); |
431 | 441 | const block = newNode.getLocation() as Blockly.BlockSvg;
|
432 | 442 | Blockly.common.setSelected(block);
|
433 |
| - } else if (drawer) { |
| 443 | + } |
| 444 | + else if (newNodeIsFieldColour) { |
| 445 | + drawer.hide(); |
| 446 | + |
| 447 | + if (oldNode?.getType() == ASTNode.types.BLOCK) { |
| 448 | + Blockly.common.setSelected(null); |
| 449 | + } else if (oldNodeIsFieldColour) { |
| 450 | + const field = oldNode.getLocation() as FieldColour; |
| 451 | + const block = field.getSourceBlock() as Blockly.BlockSvg; |
| 452 | + block.removeSelect(); |
| 453 | + } |
| 454 | + |
| 455 | + const field = newNode.getLocation() as FieldColour; |
| 456 | + const block = field.getSourceBlock() as Blockly.BlockSvg; |
| 457 | + block.addSelect(); |
| 458 | + } |
| 459 | + else { |
434 | 460 | if (oldNode?.getType() == ASTNode.types.BLOCK) {
|
435 | 461 | Blockly.common.setSelected(null);
|
| 462 | + } else if (oldNodeIsFieldColour) { |
| 463 | + const field = oldNode.getLocation() as FieldColour; |
| 464 | + const block = field.getSourceBlock() as Blockly.BlockSvg; |
| 465 | + block.removeSelect(); |
436 | 466 | }
|
437 | 467 |
|
438 | 468 | drawer.draw(oldNode, newNode);
|
|
0 commit comments