Skip to content

Commit

Permalink
fix: put highlight on shadow block when a colour field is selected (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-fenichel authored Oct 28, 2024
1 parent c2a03fc commit 25470db
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/line_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @author [email protected] (Abby Schmiedt)
*/

import { FieldColour } from '@blockly/field-colour';
import * as Blockly from 'blockly/core';
import {ASTNode, Marker} from 'blockly/core';

Expand Down Expand Up @@ -424,15 +425,44 @@ export class LineCursor extends Marker {
const oldNode = (this as any).curNode;
(this as any).curNode = newNode;
const drawer = (this as any).drawer;
if (!drawer) {
console.error('could not find a drawer');
return;
}

const newNodeIsFieldColour = newNode?.getType() == ASTNode.types.FIELD &&
(newNode.getLocation() as Blockly.Field) instanceof FieldColour;
const oldNodeIsFieldColour = oldNode?.getType() == ASTNode.types.FIELD &&
(oldNode.getLocation() as Blockly.Field) instanceof FieldColour


if (newNode?.getType() == ASTNode.types.BLOCK) {
if (drawer) {
drawer.hide();
}
drawer.hide();
const block = newNode.getLocation() as Blockly.BlockSvg;
Blockly.common.setSelected(block);
} else if (drawer) {
}
else if (newNodeIsFieldColour) {
drawer.hide();

if (oldNode?.getType() == ASTNode.types.BLOCK) {
Blockly.common.setSelected(null);
} else if (oldNodeIsFieldColour) {
const field = oldNode.getLocation() as FieldColour;
const block = field.getSourceBlock() as Blockly.BlockSvg;
block.removeSelect();
}

const field = newNode.getLocation() as FieldColour;
const block = field.getSourceBlock() as Blockly.BlockSvg;
block.addSelect();
}
else {
if (oldNode?.getType() == ASTNode.types.BLOCK) {
Blockly.common.setSelected(null);
} else if (oldNodeIsFieldColour) {
const field = oldNode.getLocation() as FieldColour;
const block = field.getSourceBlock() as Blockly.BlockSvg;
block.removeSelect();
}

drawer.draw(oldNode, newNode);
Expand Down

0 comments on commit 25470db

Please sign in to comment.