fix: improve prompting when deleting variables (#8529)

* fix: improve variable deletion behaviors.

* fix: don't prompt about deletion of only 1 variable block when triggered programmatically.

* fix: include the triggering block in the count of referencing blocks

* fix: only count the triggering block as a referencing block if it's not in the flyout
This commit is contained in:
Aaron Dodson
2024-08-19 15:47:00 -07:00
committed by GitHub
parent 64fd9ad89a
commit 14d119b204
5 changed files with 31 additions and 14 deletions

View File

@@ -165,11 +165,12 @@ const deleteOptionCallbackFactory = function (
block: VariableBlock,
): () => void {
return function () {
const workspace = block.workspace;
const variableField = block.getField('VAR') as FieldVariable;
const variable = variableField.getVariable()!;
workspace.deleteVariableById(variable.getId());
(workspace as WorkspaceSvg).refreshToolboxSelection();
const variable = variableField.getVariable();
if (variable) {
Variables.deleteVariable(variable.getWorkspace(), variable, block);
}
(block.workspace as WorkspaceSvg).refreshToolboxSelection();
};
};

View File

@@ -176,11 +176,12 @@ const renameOptionCallbackFactory = function (block: VariableBlock) {
*/
const deleteOptionCallbackFactory = function (block: VariableBlock) {
return function () {
const workspace = block.workspace;
const variableField = block.getField('VAR') as FieldVariable;
const variable = variableField.getVariable()!;
workspace.deleteVariableById(variable.getId());
(workspace as WorkspaceSvg).refreshToolboxSelection();
const variable = variableField.getVariable();
if (variable) {
Variables.deleteVariable(variable.getWorkspace(), variable, block);
}
(block.workspace as WorkspaceSvg).refreshToolboxSelection();
};
};