fix: sort extension excludes directories since only files have extensions (#3582)

This commit is contained in:
AminurAlam 2026-01-17 17:09:47 +00:00 committed by GitHub
parent a38a5e6377
commit 97d0c6bb23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
- Smart-case in interactive `cd` broken due to a typo ([#3540])
- Fix shell formatting for non-spread opener rules ([#3532])
- `sort extension` excludes directories since only files have extensions ([#3582])
- Account for URL covariance in `Url:join()` ([#3514])
## [v26.1.4]
@ -340,7 +341,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
### Fixed
- `before_ext` should exclude directories since only files have extensions ([#2132])
- `before_ext` excludes directories since only files have extensions ([#2132])
- Element style of `ui.Text` was not applied to the entire area ([#2093])
- Incorrect monorepo sub-plugin path resolution ([#2186])
- Use `u32` for parsing Linux partition blocks ([#2234])
@ -1605,3 +1606,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
[#3541]: https://github.com/sxyazi/yazi/pull/3541
[#3561]: https://github.com/sxyazi/yazi/pull/3561
[#3566]: https://github.com/sxyazi/yazi/pull/3566
[#3582]: https://github.com/sxyazi/yazi/pull/3582

View file

@ -40,12 +40,14 @@ impl FilesSorter {
if ord == Ordering::Equal { by_alphabetical(a, b) } else { ord }
}),
SortBy::Extension => items.sort_unstable_by(|a, b| {
let aa = a.url.ext().filter(|_| a.is_file());
let bb = b.url.ext().filter(|_| b.is_file());
let ord = if self.sensitive {
self.cmp(a.url.ext(), b.url.ext(), self.promote(a, b))
self.cmp(aa, bb, self.promote(a, b))
} else {
self.cmp_insensitive(
a.url.ext().map_or(&[], |s| s.encoded_bytes()),
b.url.ext().map_or(&[], |s| s.encoded_bytes()),
aa.map_or(&[], |s| s.encoded_bytes()),
bb.map_or(&[], |s| s.encoded_bytes()),
self.promote(a, b),
)
};