diff: Fix padding in file tree names
b9abe0c91b99faa0b6327908528f06437e1efc5f
1 parent
e09690ca
crates/diff/src/viewer/tree.rs
+4 -1
| 32 | 32 | /// Style for a collapsed folder containing the active file. |
|
| 33 | 33 | const SELECTED_FOLDER_STYLE: Style = Style::new(SELECTED_FOLDER_FG).bg(SELECTED_FOLDER_BG); |
|
| 34 | 34 | ||
| 35 | 35 | /// Blank columns between the file tree and the diff body. |
|
| 36 | 36 | pub(super) const GAP_COLS: usize = 1; |
|
| 37 | + | /// Blank columns after file-tree row contents. |
|
| 38 | + | const RIGHT_PADDING_COLS: usize = 1; |
|
| 37 | 39 | /// Minimum main diff columns preserved when the file tree is visible. |
|
| 38 | 40 | pub(super) const MIN_DIFF_COLS: usize = 80; |
|
| 39 | 41 | ||
| 40 | 42 | /// Selectable target in the file tree. |
|
| 41 | 43 | #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| 153 | 155 | pub fn cols(&self, view_cols: usize) -> usize { |
|
| 154 | 156 | let available = view_cols.saturating_sub(GAP_COLS + MIN_RENDER_COLS); |
|
| 155 | 157 | ||
| 156 | 158 | Tree::new(&self.model, &self.state) |
|
| 157 | 159 | .content_cols(0) |
|
| 160 | + | .saturating_add(RIGHT_PADDING_COLS) |
|
| 158 | 161 | .min(available) |
|
| 159 | 162 | } |
|
| 160 | 163 | ||
| 161 | 164 | /// Renders the file tree into `area` with an explicit active file and palette. |
|
| 162 | 165 | /// |
| 317 | 320 | } |
|
| 318 | 321 | ||
| 319 | 322 | impl Widget for FileTree { |
|
| 320 | 323 | fn size(&self, parent: Constraint) -> Size { |
|
| 321 | 324 | let tree = Tree::new(&self.model, &self.state); |
|
| 322 | - | let cols = tree.content_cols(0); |
|
| 325 | + | let cols = tree.content_cols(0).saturating_add(RIGHT_PADDING_COLS); |
|
| 323 | 326 | let rows = tree.visible_rows().len().saturating_add(TOP_PADDING_ROWS); |
|
| 324 | 327 | ||
| 325 | 328 | Size::new(cols, rows).constrain(parent) |
|
| 326 | 329 | } |
|
| 327 | 330 |
a.rs
+0 -0
b.rs
+0 -0
crates/diff/tests/golden/wide_file_tree_120x12.txt
+12 -12
| 1 | - | ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮▐ |
|
| 2 | - | ▿ rustik/ │ ⊙ a.rs 4 LOC +2 -1 │▐ |
|
| 3 | - | ⊙ a.rs ├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤▐ |
|
| 4 | - | ⊙ b.rs │ 1 1 context │▐ |
|
| 5 | - | │ 2 - old │▐ |
|
| 6 | - | │ 2 + new │▐ |
|
| 7 | - | │ 3 + extra │▐ |
|
| 8 | - | │ 3 4 tail │▐ |
|
| 9 | - | ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯▐ |
|
| 10 | - | ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮🮘 |
|
| 11 | - | │ ⊙ b.rs 2 LOC +1 -1 │🮘 |
|
| 12 | - | ├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤🮘 |
|
| 1 | + | ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮▐ |
|
| 2 | + | ▿ rustik/ │ ⊙ a.rs 4 LOC +2 -1 │▐ |
|
| 3 | + | ⊙ a.rs ├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤▐ |
|
| 4 | + | ⊙ b.rs │ 1 1 context │▐ |
|
| 5 | + | │ 2 - old │▐ |
|
| 6 | + | │ 2 + new │▐ |
|
| 7 | + | │ 3 + extra │▐ |
|
| 8 | + | │ 3 4 tail │▐ |
|
| 9 | + | ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯▐ |
|
| 10 | + | ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮🮘 |
|
| 11 | + | │ ⊙ b.rs 2 LOC +1 -1 │🮘 |
|
| 12 | + | ├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤🮘 |