From d7a646c319dd6793a0e33ce9e14f1c04cbdeebd5 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 11 Sep 2015 15:25:20 +0100 Subject: [PATCH] Fixed: Undo for delete command is broken #161 --- Assets/Fungus/Flowchart/Editor/BlockEditor.cs | 14 +++++++++----- .../Fungus/Flowchart/Editor/VariableListAdaptor.cs | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs index 42d5479a..4689de23 100644 --- a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs @@ -990,25 +990,29 @@ namespace Fungus if (command == selectedCommand) { command.OnCommandRemoved(block); - + + // Order of destruction is important here for undo to work + Undo.DestroyObjectImmediate(command); + Undo.RecordObject(flowchart.selectedBlock, "Delete"); flowchart.selectedBlock.commandList.RemoveAt(i); - Undo.DestroyObjectImmediate(command); + lastSelectedIndex = i; + break; } } } - + Undo.RecordObject(flowchart, "Delete"); flowchart.ClearSelectedCommands(); - + if (lastSelectedIndex < flowchart.selectedBlock.commandList.Count) { Command nextCommand = flowchart.selectedBlock.commandList[lastSelectedIndex]; block.GetFlowchart().AddSelectedCommand(nextCommand); } - + Repaint(); } diff --git a/Assets/Fungus/Flowchart/Editor/VariableListAdaptor.cs b/Assets/Fungus/Flowchart/Editor/VariableListAdaptor.cs index 947dc35a..61c34b9f 100644 --- a/Assets/Fungus/Flowchart/Editor/VariableListAdaptor.cs +++ b/Assets/Fungus/Flowchart/Editor/VariableListAdaptor.cs @@ -138,6 +138,11 @@ namespace Fungus { foreach (Command selectedCommand in flowchart.selectedCommands) { + if (selectedCommand == null) + { + continue; + } + if (selectedCommand.HasReference(variable)) { highlight = true;