Skip to content

Commit

Permalink
Fix: Fixed issue where renaming a tag wouldn't save the new name (#14662
Browse files Browse the repository at this point in the history
)

Co-authored-by: hishitetsu <[email protected]>
  • Loading branch information
ferrariofilippo and hishitetsu authored Feb 7, 2024
1 parent db1afa9 commit 6c9afe2
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/Files.App/Services/Settings/FileTagsSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,19 @@ public void CreateNewTag(string newTagName, string color)

public void EditTag(string uid, string name, string color)
{
var (tag, index) = GetTagAndIndex(uid);
if (tag is null)
var index = GetTagIndex(uid);
if (index == -1)
return;

tag.Name = name;
tag.Color = color;

var oldTags = FileTagList.ToList();
oldTags.RemoveAt(index);
oldTags.Insert(index, tag);
oldTags.Insert(index, new TagViewModel(name, color, uid));
FileTagList = oldTags;
}

public void DeleteTag(string uid)
{
var (_, index) = GetTagAndIndex(uid);
var index = GetTagIndex(uid);
if (index == -1)
return;

Expand Down Expand Up @@ -155,22 +152,15 @@ public override object ExportSettings()
return JsonSettingsSerializer.SerializeToJson(FileTagList);
}

private (TagViewModel?, int) GetTagAndIndex(string uid)
private int GetTagIndex(string uid)
{
TagViewModel? tag = null;
int index = -1;

for (int i = 0; i < FileTagList.Count; i++)
{
if (FileTagList[i].Uid == uid)
{
tag = FileTagList[i];
index = i;
break;
}
return i;
}

return (tag, index);
return -1;
}

private void UntagAllFiles(string uid)
Expand Down

0 comments on commit 6c9afe2

Please sign in to comment.