fix: undoing and redoing deleting procedures (#6722)

* fix: undoing and redoing deleting procedure defs

* chore: added tests for undoing and redoing procedure def deletes

* fix: dragging blocks from flyout

* chore: PR comments

* chore: fixup from rebase
This commit is contained in:
Beka Westberg
2023-01-07 00:02:45 +00:00
committed by GitHub
parent 23fb76b9f2
commit d27f7c81b4
3 changed files with 48 additions and 4 deletions

View File

@@ -308,6 +308,7 @@ const procedureDefGetDefMixin = function() {
* disposed.
*/
destroy: function() {
if (this.isInsertionMarker()) return;
this.workspace.getProcedureMap().delete(this.getProcedureModel().getId());
},
};
@@ -598,10 +599,12 @@ const procedureDefMutator = {
* parameters and statements.
*/
saveExtraState: function() {
const params = this.getProcedureModel().getParameters();
if (!params.length && this.hasStatements_) return null;
const state = Object.create(null);
state['procedureId'] = this.getProcedureModel().getId();
const params = this.getProcedureModel().getParameters();
if (!params.length && this.hasStatements_) return state;
if (params.length) {
state['params'] = params.map((p) => {
return {
@@ -625,6 +628,16 @@ const procedureDefMutator = {
* statements.
*/
loadExtraState: function(state) {
const map = this.workspace.getProcedureMap();
const procedureId = state['procedureId'];
if (procedureId && procedureId != this.model_.getId() &&
map.has(procedureId)) {
if (map.has(this.model_.getId())) {
map.delete(this.model_.getId());
}
this.model_ = map.get(procedureId);
}
if (state['params']) {
for (let i = 0; i < state['params'].length; i++) {
const {name, id, paramId} = state['params'][i];