[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.
This commit is contained in:
DoctorNefario 2021-05-05 06:16:32 +10:00 committed by GitHub
parent 4dab056d28
commit e53b4346d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
{