Files
zed/crates/csv_preview/src/settings.rs
T
Oleksandr Kholiavko f688bee4fe csv_preview: Add single-line row displaying mode (#61127)
### Changes

Adds a checkbox to toggle between multiline cells (current behavior) and
single-line rows that clip overflow, so wide CSVs stay compact when full
cell content isn't needed at a glance.

#### Demo
| Before | After |
| --- | --- |
| No single line mode | <img width="662" height="316" alt="image"
src="https://github.com/user-attachments/assets/3f2a9673-557c-4539-b755-9ff2633de2d7"
/> |
| <img width="666" height="287" alt="image"
src="https://github.com/user-attachments/assets/703f7214-a722-4fa5-9125-f043439e21b2"
/> | <img width="660" height="317" alt="image"
src="https://github.com/user-attachments/assets/be6ca912-e686-44da-90eb-58f09fab51f1"
/> |

### Testing

- Toggle "Display multiline rows" off: cells clip to one line with
ellipsis instead of wrapping
- Toggle it back on: cells wrap and grow to show full content
- Resize the window / change font size: single-line clip height tracks
the actual text line height instead of a stale hardcoded value

Release Notes:

-  N/A
2026-07-16 19:28:22 +00:00

58 lines
1.8 KiB
Rust

#[derive(Default, Clone, Copy, PartialEq)]
pub enum RowRenderMechanism {
/// More correct for multiline content, but slower.
#[default]
VariableList,
/// Default behaviour for now while resizable columns are being stabilized.
#[allow(dead_code)] // Will be used when settings ui is added
UniformList,
}
#[derive(Default, Clone, Copy)]
pub enum VerticalAlignment {
/// Align text to the top of cells
#[default]
Top,
/// Center text vertically in cells
Center,
}
#[derive(Default, Clone, Copy)]
pub enum RowIdentifiers {
/// Show original line numbers from CSV file
#[default]
SrcLines,
/// Show sequential row numbers starting from 1
RowNum,
}
#[derive(Default, Clone, Copy, PartialEq)]
pub enum FilterSortOrder {
/// Sort alphabetically (A→Z), then by number of occurrences descending within ties
#[default]
AlphaThenCount,
/// Sort by number of occurrences descending, then alphabetically within ties
CountThenAlpha,
}
#[derive(Clone, Default)]
pub(crate) struct CsvPreviewSettings {
pub(crate) rendering_with: RowRenderMechanism,
pub(crate) vertical_alignment: VerticalAlignment,
pub(crate) numbering_type: RowIdentifiers,
pub(crate) filter_sort_order: FilterSortOrder,
pub(crate) show_debug_info: bool,
#[cfg(feature = "dev-tools")]
pub(crate) show_perf_metrics_overlay: bool,
pub(crate) multiline_cells_enabled: bool,
}
impl CsvPreviewSettings {
/// `multiline_cells_enabled` only makes sense with `VariableList`, which
/// supports per-row heights; `UniformList` requires every row to share one
/// height, so multiline is never honored there regardless of the setting.
pub(crate) fn multiline_cells_effectively_enabled(&self) -> bool {
self.multiline_cells_enabled && self.rendering_with == RowRenderMechanism::VariableList
}
}