From e53b4346d799e97929518157945cbd47d153cb62 Mon Sep 17 00:00:00 2001 From: DoctorNefario <5243039+DoctorNefario@users.noreply.github.com> Date: Wed, 5 May 2021 06:16:32 +1000 Subject: [PATCH] [ColorPicker] Prevent creation of duplicate colors in history (#10705) If color already exists in history, move it to position 0. This prevents new duplicate colors, but ignores existing duplicates. --- .../ColorPickerUI/ViewModels/MainViewModel.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs index 25ddd3aaf6..7bc46756ca 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs @@ -133,7 +133,17 @@ namespace ColorPicker.ViewModels { ClipboardHelper.CopyToClipboard(ColorText); - _userSettings.ColorHistory.Insert(0, GetColorString()); + var color = GetColorString(); + + var oldIndex = _userSettings.ColorHistory.IndexOf(color); + if (oldIndex != -1) + { + _userSettings.ColorHistory.Move(oldIndex, 0); + } + else + { + _userSettings.ColorHistory.Insert(0, color); + } if (_userSettings.ColorHistory.Count > _userSettings.ColorHistoryLimit.Value) {