From 01fabde430375504353815dea6f1cb6a74463443 Mon Sep 17 00:00:00 2001 From: Dameng <313880747@qq.com> Date: Mon, 20 May 2024 14:36:45 +0800 Subject: [PATCH 1/2] fix TagInput bug when TagsProperty changed. --- src/Ursa/Controls/TagInput/TagInput.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Ursa/Controls/TagInput/TagInput.cs b/src/Ursa/Controls/TagInput/TagInput.cs index 920f01c..7b93b26 100644 --- a/src/Ursa/Controls/TagInput/TagInput.cs +++ b/src/Ursa/Controls/TagInput/TagInput.cs @@ -165,10 +165,14 @@ public class TagInput : TemplatedControl { var newTags = args.GetNewValue>(); var oldTags = args.GetOldValue>(); - for (int i = 0; i < Items.Count - 1; i++) + + // remove all tags except the textbox + int count = Items.Count; + for (int i = 0; i < count - 1; i++) { - Items.RemoveAt(Items.Count - 1); + Items.RemoveAt(0); } + if (newTags != null) { for (int i = 0; i < newTags.Count; i++) From 1f86569ce5583c4c44c139366c7b94375d4467c4 Mon Sep 17 00:00:00 2001 From: Dameng <313880747@qq.com> Date: Mon, 20 May 2024 16:11:51 +0800 Subject: [PATCH 2/2] prefer AvaloniaList.RemoveRange for the performance. --- src/Ursa/Controls/TagInput/TagInput.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Ursa/Controls/TagInput/TagInput.cs b/src/Ursa/Controls/TagInput/TagInput.cs index 7b93b26..30773d4 100644 --- a/src/Ursa/Controls/TagInput/TagInput.cs +++ b/src/Ursa/Controls/TagInput/TagInput.cs @@ -166,11 +166,14 @@ public class TagInput : TemplatedControl var newTags = args.GetNewValue>(); var oldTags = args.GetOldValue>(); - // remove all tags except the textbox - int count = Items.Count; - for (int i = 0; i < count - 1; i++) + if (Items is AvaloniaList avaloniaList) { - Items.RemoveAt(0); + avaloniaList.RemoveRange(0, avaloniaList.Count - 1); + } + else if (Items.Count != 0) + { + Items.Clear(); + Items.Add(_textBox); } if (newTags != null)