FileFinder: use idiomatic definition for Ord/PartialOrd (#6851)

This commit is contained in:
Alex Kladov 2024-01-27 11:07:24 +00:00 committed by GitHub
parent 536a4ab87a
commit 1f83b5c508
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -156,26 +156,24 @@ struct ProjectPanelOrdMatch(PathMatch);
impl Ord for ProjectPanelOrdMatch { impl Ord for ProjectPanelOrdMatch {
fn cmp(&self, other: &Self) -> cmp::Ordering { fn cmp(&self, other: &Self) -> cmp::Ordering {
self.partial_cmp(other).unwrap() self.0
.score
.partial_cmp(&other.0.score)
.unwrap_or(cmp::Ordering::Equal)
.then_with(|| self.0.worktree_id.cmp(&other.0.worktree_id))
.then_with(|| {
other
.0
.distance_to_relative_ancestor
.cmp(&self.0.distance_to_relative_ancestor)
})
.then_with(|| self.0.path.cmp(&other.0.path).reverse())
} }
} }
impl PartialOrd for ProjectPanelOrdMatch { impl PartialOrd for ProjectPanelOrdMatch {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
Some( Some(self.cmp(other))
self.0
.score
.partial_cmp(&other.0.score)
.unwrap_or(cmp::Ordering::Equal)
.then_with(|| self.0.worktree_id.cmp(&other.0.worktree_id))
.then_with(|| {
other
.0
.distance_to_relative_ancestor
.cmp(&self.0.distance_to_relative_ancestor)
})
.then_with(|| self.0.path.cmp(&other.0.path).reverse()),
)
} }
} }