Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of fixes for bugs found on livestream #10392

Merged
merged 4 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pxtblocks/builtins/loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export function initLoops() {
{
"type": "field_variable",
"name": "VAR",
"variable": controlsSimpleForDef.block["variable"]
"variable": controlsSimpleForDef.block["variable"],
"variableTypes": [""],
// Please note that most multilingual characters
// cannot be used as variable name at this point.
// Translate or decide the default variable name
Expand Down Expand Up @@ -328,7 +329,8 @@ export function initLoops() {
{
"type": "field_variable",
"name": "VAR",
"variable": controlsForOfDef.block["variable"]
"variable": controlsForOfDef.block["variable"],
"variableTypes": [""],
// Please note that most multilingual characters
// cannot be used as variable name at this point.
// Translate or decide the default variable name
Expand Down
66 changes: 57 additions & 9 deletions pxtblocks/builtins/variables.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import * as Blockly from "blockly";
import { createFlyoutGroupLabel, createFlyoutHeadingLabel, mkVariableFieldBlock } from "../toolbox";
import { installBuiltinHelpInfo, setBuiltinHelpInfo } from "../help";
import { provider } from "../constants";

export function initVariables() {
// We only give types to "special" variables like enum members and we don't
// want those showing up in the variable dropdown so filter the variables
// that show up to only ones that have an empty type
(Blockly.FieldVariable.prototype as any).getVariableTypes_ = () => [""];

let varname = lf("{id:var}item");
Blockly.Variables.flyoutCategory = function (workspace: Blockly.WorkspaceSvg) {
let xmlList: HTMLElement[] = [];
Expand Down Expand Up @@ -103,7 +97,31 @@ export function initVariables() {
const variablesGetId = "variables_get";
const variablesGetDef = pxt.blocks.getBlockDefinition(variablesGetId);
msg.VARIABLES_GET_CREATE_SET = variablesGetDef.block["VARIABLES_GET_CREATE_SET"];
installBuiltinHelpInfo(variablesGetId);
Blockly.Blocks[variablesGetId] = {
init: function() {
this.jsonInit(
{
"type": "variables_get",
"message0": "%1",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
"variableTypes": [""],
},
],
"output": null,
"style": "variable_blocks",
"helpUrl": "%{BKY_VARIABLES_GET_HELPURL}",
"tooltip": "%{BKY_VARIABLES_GET_TOOLTIP}",
"extensions": ["contextMenu_variableSetterGetter"],
}
);

setBuiltinHelpInfo(this, variablesGetId);
}
};

const variablesReporterGetId = "variables_get_reporter";
installBuiltinHelpInfo(variablesReporterGetId);
Expand All @@ -120,7 +138,36 @@ export function initVariables() {
msg.VARIABLES_SET = variablesSetDef.block["VARIABLES_SET"];
msg.VARIABLES_DEFAULT_NAME = varname;
msg.VARIABLES_SET_CREATE_GET = lf("Create 'get %1'");
installBuiltinHelpInfo(variablesSetId);
Blockly.Blocks[variablesSetId] = {
init: function() {
this.jsonInit(
{
"type": "variables_set",
"message0": "%{BKY_VARIABLES_SET}",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
"variableTypes": [""],
},
{
"type": "input_value",
"name": "VALUE",
},
],
"previousStatement": null,
"nextStatement": null,
"style": "variable_blocks",
"tooltip": "%{BKY_VARIABLES_SET_TOOLTIP}",
"helpUrl": "%{BKY_VARIABLES_SET_HELPURL}",
"extensions": ["contextMenu_variableSetterGetter"],
}
);

setBuiltinHelpInfo(this, variablesSetId);
}
};

// pxt variables_change
const variablesChangeId = "variables_change";
Expand All @@ -133,7 +180,8 @@ export function initVariables() {
{
"type": "field_variable",
"name": "VAR",
"variable": varname
"variable": varname,
"variableTypes": [""]
},
{
"type": "input_value",
Expand Down
1 change: 0 additions & 1 deletion pxtblocks/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function installHelpResources(id: string, name: string, tooltip: any, url

block.init = function () {
old.call(this);
let block = this;
setHelpResources(this, id, name, tooltip, url, colour, colourSecondary, colourTertiary);
}
}
Expand Down
3 changes: 2 additions & 1 deletion pxtblocks/plugins/duplicateOnDrag/variablesGetReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Blockly.defineBlocksWithJsonArray([
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}"
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
"variableTypes": [""],
}
],
"output": null,
Expand Down
2 changes: 2 additions & 0 deletions pxtlib/spriteutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ namespace pxt.sprite {
}

export function bitmapEquals(a: pxt.sprite.BitmapData, b: pxt.sprite.BitmapData) {
if (a === b) return true;
else if (!a && b || !b && a) return false;
return pxt.sprite.Bitmap.fromData(a).equals(pxt.sprite.Bitmap.fromData(b));
}

Expand Down
9 changes: 8 additions & 1 deletion webapp/src/components/ImageEditor/ImageCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple
if (document.activeElement instanceof HTMLElement && document.activeElement !== this.refs["canvas-bounds"]) {
document.activeElement.blur();
}
(this.refs["canvas-bounds"] as HTMLDivElement).focus();
this.focus();

if (this.isColorSelect()) {
this.selectCanvasColor(coord, isRightClick);
Expand All @@ -230,6 +230,7 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple

onDragStart(coord: ClientCoordinates, isRightClick?: boolean): void {
this.hasInteracted = true
this.focus();
if (this.touchesResize(coord.clientX, coord.clientY)) {
this.isResizing = true;
}
Expand All @@ -243,10 +244,12 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple
else {
this.updateCursorLocation(coord);
this.startEdit(!!isRightClick);
this.updateEdit(this.cursorLocation[0], this.cursorLocation[1]);
}
}

onDragMove(coord: ClientCoordinates): void {
this.focus();
if (this.isPanning() && this.lastPanX != undefined && this.lastPanY != undefined) {
this.panX += this.lastPanX - coord.clientX;
this.panY += this.lastPanY - coord.clientY;
Expand Down Expand Up @@ -1091,6 +1094,10 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple

this.props.dispatchImageEdit(this.editState.toImageState());
}

protected focus() {
(this.refs["canvas-bounds"] as HTMLDivElement).focus();
}
}

function mapStateToProps({ store: { present }, editor }: ImageEditorStore, ownProps: any) {
Expand Down