mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
support rename variable
This commit is contained in:
parent
6fa49b1e7a
commit
7f1f9079e3
2 changed files with 14 additions and 1 deletions
|
@ -298,7 +298,7 @@ class Blocks {
|
|||
if (!block.fields[args.name]) return;
|
||||
if (args.name === 'VARIABLE') {
|
||||
// Get variable name using the id in args.value.
|
||||
const variable = optRuntime.getEditingTarget().lookupVariableById(args.value);
|
||||
const variable = optRuntime.getEditingTarget().lookupVariableById(args.id);
|
||||
if (variable) {
|
||||
block.fields[args.name].value = variable.name;
|
||||
block.fields[args.name].id = args.value;
|
||||
|
|
|
@ -4,6 +4,7 @@ const Blocks = require('./blocks');
|
|||
const Variable = require('../engine/variable');
|
||||
const List = require('../engine/list');
|
||||
const uid = require('../util/uid');
|
||||
const {Map} = require('immutable');
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
|
@ -161,6 +162,17 @@ class Target extends EventEmitter {
|
|||
const variable = this.variables[id];
|
||||
if (variable.id === id) {
|
||||
variable.name = newName;
|
||||
const blocks = this.runtime.monitorBlocks;
|
||||
blocks.changeBlock({
|
||||
id: id,
|
||||
element: 'field',
|
||||
name: 'VARIABLE',
|
||||
value: newName
|
||||
}, this.runtime);
|
||||
this.runtime.requestUpdateMonitor(Map({
|
||||
id: id,
|
||||
params: blocks._getBlockParams(blocks.getBlock(variable.id))
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +184,7 @@ class Target extends EventEmitter {
|
|||
deleteVariable (id) {
|
||||
if (this.variables.hasOwnProperty(id)) {
|
||||
delete this.variables[id];
|
||||
this.runtime.requestRemoveMonitor(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue