From 6a660c7d45395b4a3c61ef0cc17cd351a548baf2 Mon Sep 17 00:00:00 2001 From: MaxED Date: Wed, 6 Jul 2016 00:15:19 +0000 Subject: [PATCH] Fixed several cases when sector/linedef tag changes were incorrectly recorded by undo system. --- Source/Core/Map/MapSet.cs | 24 +++++++++++-------- .../FindReplace/FindLinedefTags.cs | 6 +++-- .../FindReplace/FindSectorTags.cs | 6 +++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Source/Core/Map/MapSet.cs b/Source/Core/Map/MapSet.cs index 1a91404..b0d1a21 100644 --- a/Source/Core/Map/MapSet.cs +++ b/Source/Core/Map/MapSet.cs @@ -3542,18 +3542,20 @@ namespace CodeImp.DoomBuilder.Map { //mxd. Multiple tags support... bool changed = false; - for(int i = 0; i < s.Tags.Count; i++) + // Make a copy of tags, otherwise BeforePropsChange will be triggered after tag changes + List tags = new List(s.Tags); + for(int i = 0; i < tags.Count; i++) { - int tag = s.Tags[i]; + int tag = tags[i]; handler(s, false, UniversalType.SectorTag, ref tag, obj); - if(tag != s.Tags[i]) + if(tag != tags[i]) { - s.Tags[i] = tag; + tags[i] = tag; changed = true; } } - if(changed) s.Tags = s.Tags.Distinct().ToList(); + if(changed) s.Tags = tags.Distinct().ToList(); } } @@ -3601,18 +3603,20 @@ namespace CodeImp.DoomBuilder.Map { //mxd. Multiple tags support... bool changed = false; - for(int i = 0; i < l.Tags.Count; i++) + // Make a copy of tags, otherwise BeforePropsChange will be triggered after tag changes + List tags = new List(l.Tags); + for(int i = 0; i < tags.Count; i++) { - int tag = l.Tags[i]; + int tag = tags[i]; handler(l, false, UniversalType.LinedefTag, ref tag, obj); - if(tag != l.Tags[i]) + if(tag != tags[i]) { - l.Tags[i] = tag; + tags[i] = tag; changed = true; } } - if(changed) l.Tags = l.Tags.Distinct().ToList(); + if(changed) l.Tags = tags.Distinct().ToList(); } } } diff --git a/Source/Plugins/BuilderModes/FindReplace/FindLinedefTags.cs b/Source/Plugins/BuilderModes/FindReplace/FindLinedefTags.cs index f1f28c6..5945193 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindLinedefTags.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindLinedefTags.cs @@ -129,8 +129,10 @@ namespace CodeImp.DoomBuilder.BuilderModes // Replace if(replace) { - l.Tags[index] = replacetag; //mxd - l.Tags = l.Tags.Distinct().ToList(); //mxd. We don't want duplicates + //mxd. Make a copy of tags, otherwise BeforePropsChange will be triggered after tag changes + List tags = new List(l.Tags); + tags[index] = replacetag; + l.Tags = tags.Distinct().ToList(); // We don't want duplicates } // Add to list diff --git a/Source/Plugins/BuilderModes/FindReplace/FindSectorTags.cs b/Source/Plugins/BuilderModes/FindReplace/FindSectorTags.cs index 6df542d..c0d82a2 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindSectorTags.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindSectorTags.cs @@ -122,8 +122,10 @@ namespace CodeImp.DoomBuilder.BuilderModes // Replace if(replace) { - s.Tags[index] = replacetag; //mxd - s.Tags = s.Tags.Distinct().ToList(); //mxd. We don't want duplicates + //mxd. Make a copy of tags, otherwise BeforePropsChange will be triggered after tag changes + List tags = new List(s.Tags); + tags[index] = replacetag; + s.Tags = tags.Distinct().ToList(); // We don't want duplicates } // Add to list