Skip to content

Commit

Permalink
Hide context around collapsed editable sections
Browse files Browse the repository at this point in the history
This makes the file view tidier by hiding context sections which aren't
contiguous to at least editable section that is expanded.
  • Loading branch information
emesterhazy committed May 5, 2024
1 parent b468eaa commit 1c06202
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,28 @@ impl Component for FileView<'_> {
if self.is_expanded() {
let x = x + 2;
let mut section_y = y + file_view_header_rect.height.unwrap_isize();
for section_view in section_views {
// Find the indexes of sections that are expanded and editable.
let expanded_sections: Vec<usize> = section_views
.iter()
.enumerate()
.filter_map(|(ix, s_view)| {
if s_view.is_expanded() && s_view.section.is_editable() {
return Some(ix);
}
None
})
.collect();
for (ix, section_view) in section_views.iter().enumerate() {
// Skip this section if it is an un-editable context section and
// none of the editable sections surrounding it are expanded.
let context_section = !section_view.section.is_editable();
let previous_collapsed =
ix == 0 || expanded_sections.binary_search(&(ix - 1)).is_err();
let following_collapsed = expanded_sections.binary_search(&(ix + 1)).is_err();
if context_section && previous_collapsed && following_collapsed {
continue;
}

let section_rect = viewport.draw_component(x, section_y, section_view);
section_y += section_rect.height.unwrap_isize();

Expand Down

0 comments on commit 1c06202

Please sign in to comment.