mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
fix: Wrap toolbox refreshes in a timeout when modifying variables (#8980)
This commit is contained in:
@@ -21,7 +21,6 @@ import '../core/field_label.js';
|
|||||||
import {FieldVariable} from '../core/field_variable.js';
|
import {FieldVariable} from '../core/field_variable.js';
|
||||||
import {Msg} from '../core/msg.js';
|
import {Msg} from '../core/msg.js';
|
||||||
import * as Variables from '../core/variables.js';
|
import * as Variables from '../core/variables.js';
|
||||||
import type {WorkspaceSvg} from '../core/workspace_svg.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dictionary of the block definitions provided by this module.
|
* A dictionary of the block definitions provided by this module.
|
||||||
@@ -170,7 +169,6 @@ const deleteOptionCallbackFactory = function (
|
|||||||
if (variable) {
|
if (variable) {
|
||||||
Variables.deleteVariable(variable.getWorkspace(), variable, block);
|
Variables.deleteVariable(variable.getWorkspace(), variable, block);
|
||||||
}
|
}
|
||||||
(block.workspace as WorkspaceSvg).refreshToolboxSelection();
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import '../core/field_label.js';
|
|||||||
import {FieldVariable} from '../core/field_variable.js';
|
import {FieldVariable} from '../core/field_variable.js';
|
||||||
import {Msg} from '../core/msg.js';
|
import {Msg} from '../core/msg.js';
|
||||||
import * as Variables from '../core/variables.js';
|
import * as Variables from '../core/variables.js';
|
||||||
import type {WorkspaceSvg} from '../core/workspace_svg.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dictionary of the block definitions provided by this module.
|
* A dictionary of the block definitions provided by this module.
|
||||||
@@ -181,7 +180,6 @@ const deleteOptionCallbackFactory = function (block: VariableBlock) {
|
|||||||
if (variable) {
|
if (variable) {
|
||||||
Variables.deleteVariable(variable.getWorkspace(), variable, block);
|
Variables.deleteVariable(variable.getWorkspace(), variable, block);
|
||||||
}
|
}
|
||||||
(block.workspace as WorkspaceSvg).refreshToolboxSelection();
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import * as dom from './utils/dom.js';
|
|||||||
import * as parsing from './utils/parsing.js';
|
import * as parsing from './utils/parsing.js';
|
||||||
import {Size} from './utils/size.js';
|
import {Size} from './utils/size.js';
|
||||||
import * as Variables from './variables.js';
|
import * as Variables from './variables.js';
|
||||||
import {WorkspaceSvg} from './workspace_svg.js';
|
|
||||||
import * as Xml from './xml.js';
|
import * as Xml from './xml.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -523,9 +522,6 @@ export class FieldVariable extends FieldDropdown {
|
|||||||
// Delete variable.
|
// Delete variable.
|
||||||
const workspace = this.variable.getWorkspace();
|
const workspace = this.variable.getWorkspace();
|
||||||
Variables.deleteVariable(workspace, this.variable, this.sourceBlock_);
|
Variables.deleteVariable(workspace, this.variable, this.sourceBlock_);
|
||||||
if (workspace instanceof WorkspaceSvg) {
|
|
||||||
workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import * as deprecation from './utils/deprecation.js';
|
|||||||
import * as idGenerator from './utils/idgenerator.js';
|
import * as idGenerator from './utils/idgenerator.js';
|
||||||
import {deleteVariable, getVariableUsesById} from './variables.js';
|
import {deleteVariable, getVariableUsesById} from './variables.js';
|
||||||
import type {Workspace} from './workspace.js';
|
import type {Workspace} from './workspace.js';
|
||||||
import {WorkspaceSvg} from './workspace_svg.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for a variable map. This contains a dictionary data structure with
|
* Class for a variable map. This contains a dictionary data structure with
|
||||||
@@ -93,9 +92,6 @@ export class VariableMap
|
|||||||
} finally {
|
} finally {
|
||||||
eventUtils.setGroup(existingGroup);
|
eventUtils.setGroup(existingGroup);
|
||||||
}
|
}
|
||||||
if (this.workspace instanceof WorkspaceSvg) {
|
|
||||||
this.workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
return variable;
|
return variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,9 +108,6 @@ export class VariableMap
|
|||||||
if (!this.variableMap.has(newType)) {
|
if (!this.variableMap.has(newType)) {
|
||||||
this.variableMap.set(newType, newTypeVariables);
|
this.variableMap.set(newType, newTypeVariables);
|
||||||
}
|
}
|
||||||
if (this.workspace instanceof WorkspaceSvg) {
|
|
||||||
this.workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
return variable;
|
return variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,9 +154,6 @@ export class VariableMap
|
|||||||
for (let i = 0; i < blocks.length; i++) {
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
blocks[i].updateVarName(variable);
|
blocks[i].updateVarName(variable);
|
||||||
}
|
}
|
||||||
if (this.workspace instanceof WorkspaceSvg) {
|
|
||||||
this.workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,9 +249,6 @@ export class VariableMap
|
|||||||
this.variableMap.set(type, variables);
|
this.variableMap.set(type, variables);
|
||||||
}
|
}
|
||||||
eventUtils.fire(new (eventUtils.get(EventType.VAR_CREATE))(variable));
|
eventUtils.fire(new (eventUtils.get(EventType.VAR_CREATE))(variable));
|
||||||
if (this.workspace instanceof WorkspaceSvg) {
|
|
||||||
this.workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
return variable;
|
return variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,9 +266,6 @@ export class VariableMap
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.variableMap.get(type)?.set(variable.getId(), variable);
|
this.variableMap.get(type)?.set(variable.getId(), variable);
|
||||||
if (this.workspace instanceof WorkspaceSvg) {
|
|
||||||
this.workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Begin functions for variable deletion. */
|
/* Begin functions for variable deletion. */
|
||||||
@@ -310,9 +294,6 @@ export class VariableMap
|
|||||||
} finally {
|
} finally {
|
||||||
eventUtils.setGroup(existingGroup);
|
eventUtils.setGroup(existingGroup);
|
||||||
}
|
}
|
||||||
if (this.workspace instanceof WorkspaceSvg) {
|
|
||||||
this.workspace.refreshToolboxSelection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import {
|
|||||||
ContextMenuRegistry,
|
ContextMenuRegistry,
|
||||||
} from './contextmenu_registry.js';
|
} from './contextmenu_registry.js';
|
||||||
import * as dropDownDiv from './dropdowndiv.js';
|
import * as dropDownDiv from './dropdowndiv.js';
|
||||||
|
import {Abstract as AbstractEvent} from './events/events.js';
|
||||||
import {EventType} from './events/type.js';
|
import {EventType} from './events/type.js';
|
||||||
import * as eventUtils from './events/utils.js';
|
import * as eventUtils from './events/utils.js';
|
||||||
import {Flyout} from './flyout_base.js';
|
import {Flyout} from './flyout_base.js';
|
||||||
@@ -399,6 +400,9 @@ export class WorkspaceSvg
|
|||||||
this.addChangeListener(Procedures.mutatorOpenListener);
|
this.addChangeListener(Procedures.mutatorOpenListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up callbacks to refresh the toolbox when variables change
|
||||||
|
this.addChangeListener(this.variableChangeCallback.bind(this));
|
||||||
|
|
||||||
/** Object in charge of storing and updating the workspace theme. */
|
/** Object in charge of storing and updating the workspace theme. */
|
||||||
this.themeManager_ = this.options.parentWorkspace
|
this.themeManager_ = this.options.parentWorkspace
|
||||||
? this.options.parentWorkspace.getThemeManager()
|
? this.options.parentWorkspace.getThemeManager()
|
||||||
@@ -1361,6 +1365,23 @@ export class WorkspaceSvg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles any necessary updates when a variable changes.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
variableChangeCallback(event: AbstractEvent) {
|
||||||
|
switch (event.type) {
|
||||||
|
case EventType.VAR_CREATE:
|
||||||
|
case EventType.VAR_DELETE:
|
||||||
|
case EventType.VAR_RENAME:
|
||||||
|
case EventType.VAR_TYPE_CHANGE:
|
||||||
|
this.refreshToolboxSelection();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh the toolbox unless there's a drag in progress.
|
* Refresh the toolbox unless there's a drag in progress.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user