fix(TimeLayoutItem):修复了在时间表中点击刷新按钮时,若时间表中存在两个起始时间相同的项就会发生顺序跳变的问题(issue#1820)#1839
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73cf66f8e2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return -1; | ||
| } | ||
|
|
||
| if (o.EndTime > EndTime) |
There was a problem hiding this comment.
Preserve order for exactly equal time points
When two zero-duration items share the same timestamp, such as a separator and an action, this new tie-breaker still falls through to return 0 because both StartTime and EndTime match. UpdateTimeLayout() uses List.Sort() followed by Reverse(), and List.Sort() is not stable for items that compare equal, so refreshing can still reorder those valid same-time entries; the fix needs a deterministic final tie-breaker or a stable sort that preserves original order.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
实际使用场景中不太可能同时设定两个开始时间和结束时间相同的项。
|
感谢您的贡献🤝 @all-contributors please add @wan-an-zz for code |
|
I've put up a pull request to add @wan-an-zz! 🎉 |

这个 Pull Request 做了什么?
问题复现
编辑档案 -> 时间表 -> 添加一个开始时间和结束时间相同的项(如分割线) -> 再添加一个开始时间和刚刚添加的那个相同的项 -> 反复点击“刷新”按钮 -> 每次点击“刷新”按钮,这两个项的顺序都会发生变化
问题溯源
当“刷新”按钮被点击时,调用了
ClassIsland.Views.ProfileSettingsWindow.UpdateTimeLayout()方法,该方法内会对TimeLayout.Layouts集合进行排序,由于该集合内部的元素实现了IComparable接口,排序时会调用CompareTo()方法对集合内部的各项元素进行比较,但是该方法只比较了每个TimeLayoutItem的StartTime(开始时间)而没有比较EndTime(结束时间),导致在排序时两个开始时间相同的项会在点击“刷新”按钮后发生顺序跳变修复
在
CompareTo()方法内加入对EndTime的比较相关 Issue
Fixes #1820
检查清单