diff: Clear stale file tree selections
0df9b0651af74c2dc31bfedd5e69b4be9205f20e
Clear the file tree viewport before repainting rows so moving the cursor cannot leave selected backgrounds behind. Assisted-by: Codex:gpt-5.6
1 parent
4d8663d4
crates/diff/src/viewer/tree.rs
+7 -1
| 3 | 3 | use std::collections::BTreeSet; |
|
| 4 | 4 | use std::path::PathBuf; |
|
| 5 | 5 | ||
| 6 | 6 | use rustik_tui as tui; |
|
| 7 | 7 | use tui::{ |
|
| 8 | - | Buffer, Color, Constraint, Label, Placement, Point, Rect, Size, Style, Tree, TreeHitZone, |
|
| 8 | + | Buffer, Cell, Color, Constraint, Label, Placement, Point, Rect, Size, Style, Tree, TreeHitZone, |
|
| 9 | 9 | TreeModel, TreeNodeKind, TreeRow, TreeState, TreeStyle, Widget, |
|
| 10 | 10 | }; |
|
| 11 | 11 | ||
| 12 | 12 | use super::{DiffPalette, FILE_KIND_BADGE_FG, MIN_RENDER_COLS}; |
|
| 13 | 13 | use crate::{DiffDecorator, DiffDocument, FileId, FileKind}; |
| 187 | 187 | active_file, |
|
| 188 | 188 | collapsed, |
|
| 189 | 189 | palette, |
|
| 190 | 190 | decorator, |
|
| 191 | 191 | }; |
|
| 192 | + | buf.fill(tree_area, Cell::blank()); |
|
| 193 | + | ||
| 192 | 194 | let tree = Tree::new(&styled, &self.state).style(FILE_TREE_STYLE); |
|
| 193 | 195 | let rows = tree.visible_rows(); |
|
| 194 | 196 | let view = tree.selected_view(&rows, tree_area.rows, Placement::Minimal); |
|
| 195 | 197 | ||
| 196 | 198 | view.render_rows(tree_area, buf, |row, cols| tree.render_row(rows[row], cols)); |
| 638 | 640 | } |
|
| 639 | 641 | ||
| 640 | 642 | #[cfg(test)] |
|
| 641 | 643 | #[allow(clippy::unwrap_used)] |
|
| 642 | 644 | mod tests { |
|
| 645 | + | use super::*; |
|
| 646 | + | ||
| 647 | + | use rustik_tui::{Buffer, Color, Rect, Widget}; |
|
| 648 | + | ||
| 643 | 649 | use crate::{Decode, DiffDocument, DiffOptions, DiffViewer}; |
|
| 644 | 650 | ||
| 645 | 651 | fn two_file_viewer() -> DiffViewer { |
|
| 646 | 652 | let document = DiffDocument::decode_str( |
|
| 647 | 653 | "\ |
a.rs
+0 -0
b.rs
+0 -0