From 8eb2fd211fcb6dee043382037eaab7a4162eff16 Mon Sep 17 00:00:00 2001
From: Oleksandr Kholiavko <43780952+HalavicH@users.noreply.github.com>
Date: Mon, 5 Oct 2026 16:57:01 +0000
Subject: [PATCH] tabular_data_preview: Sort filter options natually (#64764)
## Problem
Column filter dropdown options in `tabular_data_preview` were sorted
with standard lexicographical comparison (`a.content.cmp(&b.content)`).
This led to unnatural ordering for numbers and mixed alphanumeric values
(e.g., `"item 10"` sorting before `"item 2"`).
## Solution
Switched to `util::paths::natural_sort` based comparison:
- Compares numeric segments by numerical value rather than
lexicographically (e.g., `1`, `2`, `10` instead of `1`, `10`, `2`).
- Performs case-insensitive comparison with case-sensitive tie-breaking.
- Keeps `None`/null values sorted at the bottom of the filter list.
## Testing
- Added unit tests in `table_header.rs` covering numeric runs, case
insensitivity, and null value placement.
- `cargo test -p tabular_data_preview`
- `./script/clippy -p tabular_data_preview` clean.
## Showcase
| Before | After |
| --- | --- |
|
|
|
## Self-Review Checklist:
- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] UI standards followed
- [x] Tests cover the new/changed behavior
- [x] Performance impact considered, acceptable
Release Notes:
- Improved column filter dropdown in tabular data preview to sort values
naturally (e.g., `2` before `10`).
---------
Co-authored-by: MrSubidubi
---
crates/tabular_data_preview/Cargo.toml | 2 +-
.../src/renderer/table_header.rs | 24 +++++++++++++++++--
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/crates/tabular_data_preview/Cargo.toml b/crates/tabular_data_preview/Cargo.toml
index d61635bbfc4..092353cd350 100644
--- a/crates/tabular_data_preview/Cargo.toml
+++ b/crates/tabular_data_preview/Cargo.toml
@@ -22,12 +22,12 @@ serde.workspace = true
serde_json.workspace = true
schemars.workspace = true
text.workspace = true
+util.workspace = true
[dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
project = { workspace = true, features = ["test-support"] }
proptest.workspace = true
-util.workspace = true
workspace = { workspace = true, features = ["test-support"] }
[features]
diff --git a/crates/tabular_data_preview/src/renderer/table_header.rs b/crates/tabular_data_preview/src/renderer/table_header.rs
index 1636f584433..cb58bedc1ae 100644
--- a/crates/tabular_data_preview/src/renderer/table_header.rs
+++ b/crates/tabular_data_preview/src/renderer/table_header.rs
@@ -1,5 +1,6 @@
use std::{
borrow::Cow,
+ cmp,
collections::HashMap,
sync::{
Arc,
@@ -28,6 +29,25 @@ use crate::{
types::AnyColumn,
};
+#[derive(PartialEq, Eq)]
+struct NaturallyOrdered<'a>(&'a str);
+
+impl Ord for NaturallyOrdered<'_> {
+ fn cmp(&self, other: &Self) -> cmp::Ordering {
+ util::paths::natural_sort(self.0, other.0)
+ }
+}
+
+impl PartialOrd for NaturallyOrdered<'_> {
+ fn partial_cmp(&self, other: &Self) -> Option {
+ Some(self.cmp(other))
+ }
+}
+
+fn natural_content(entry: &FilterEntry) -> Option> {
+ entry.content.as_deref().map(NaturallyOrdered)
+}
+
struct ColumnFilterRow {
entry: FilterEntry,
is_applied: bool,
@@ -90,14 +110,14 @@ impl ColumnFilterDelegate {
FilterSortOrder::AlphaThenCount => available.sort_by(|(a, a_app), (b, b_app)| {
b_app
.cmp(a_app)
- .then_with(|| a.content.cmp(&b.content))
+ .then_with(|| natural_content(a).cmp(&natural_content(b)))
.then_with(|| b.occurred_times().cmp(&a.occurred_times()))
}),
FilterSortOrder::CountThenAlpha => available.sort_by(|(a, a_app), (b, b_app)| {
b_app
.cmp(a_app)
.then_with(|| b.occurred_times().cmp(&a.occurred_times()))
- .then_with(|| a.content.cmp(&b.content))
+ .then_with(|| natural_content(a).cmp(&natural_content(b)))
}),
}