fix: wrap explorer root paths in narrow panes
This commit is contained in:
+45
-8
@@ -26,7 +26,7 @@ use ratatui::{
|
||||
layout::{Constraint, Layout, Position, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Clear, Paragraph},
|
||||
widgets::{Block, Borders, Clear, Paragraph, Wrap},
|
||||
};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
@@ -2263,9 +2263,22 @@ fn draw_file_list(
|
||||
let show_root = content.height >= 4 && !picker.root.as_os_str().is_empty();
|
||||
let show_error = picker.error.is_some() && content.height >= 2;
|
||||
let show_help = content.height >= 5 + u16::from(show_error);
|
||||
let root = show_root.then(|| {
|
||||
Paragraph::new(display_text(&picker.root.to_string_lossy()))
|
||||
.style(Style::default().fg(Color::DarkGray))
|
||||
.wrap(Wrap { trim: false })
|
||||
});
|
||||
// Reserve the query, optional notices/footer, and at least one file row.
|
||||
let root_rows = root.as_ref().map_or(0, |root| {
|
||||
root.line_count(content.width).min(usize::from(
|
||||
content
|
||||
.height
|
||||
.saturating_sub(2 + u16::from(show_error) + u16::from(show_help)),
|
||||
)) as u16
|
||||
});
|
||||
let [query_area, root_area, error_area, results_area, help_area] = Layout::vertical([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(u16::from(show_root)),
|
||||
Constraint::Length(root_rows),
|
||||
Constraint::Length(u16::from(show_error)),
|
||||
Constraint::Fill(1),
|
||||
Constraint::Length(u16::from(show_help)),
|
||||
@@ -2304,12 +2317,8 @@ fn draw_file_list(
|
||||
let cursor_x = if browsing { 0 } else { query_width - offset };
|
||||
frame.set_cursor_position((query_area.x + cursor_x as u16, query_area.y));
|
||||
}
|
||||
if show_root {
|
||||
frame.render_widget(
|
||||
Paragraph::new(display_text(&picker.root.to_string_lossy()))
|
||||
.style(Style::default().fg(Color::DarkGray)),
|
||||
root_area,
|
||||
);
|
||||
if let Some(root) = root {
|
||||
frame.render_widget(root, root_area);
|
||||
}
|
||||
if show_error {
|
||||
frame.render_widget(
|
||||
@@ -5824,6 +5833,34 @@ end
|
||||
assert_eq!(buffer[(1, selected_y)].bg, Color::Blue);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explorer_wraps_only_root_path_and_reserves_file_rows_in_short_panes() {
|
||||
let root = "/a/very/long/path/to/project/root";
|
||||
let picker = FilePicker::from_paths(root.into(), [(0, "entry.txt".into())]);
|
||||
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(20, 12)).unwrap();
|
||||
let mut panels = WheelPanels::default();
|
||||
terminal
|
||||
.draw(|frame| draw_file_list(frame, &picker, frame.area(), "", &mut panels, None))
|
||||
.unwrap();
|
||||
let buffer = terminal.backend().buffer();
|
||||
let path = (2..4)
|
||||
.map(|y| (1..19).map(|x| buffer[(x, y)].symbol()).collect::<String>())
|
||||
.collect::<String>();
|
||||
assert_eq!(path.trim_end(), root);
|
||||
assert!(
|
||||
screen_text(&terminal)
|
||||
.lines()
|
||||
.nth(4)
|
||||
.unwrap()
|
||||
.contains("entry.txt")
|
||||
);
|
||||
terminal.backend_mut().resize(20, 6);
|
||||
terminal
|
||||
.draw(|frame| draw_file_list(frame, &picker, frame.area(), "", &mut panels, None))
|
||||
.unwrap();
|
||||
assert!(screen_text(&terminal).contains("entry.txt"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_footers_show_remapped_and_disabled_selection_keys() {
|
||||
let mut editor = Editor::open(None, vec![]).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user