refactor: apply review cuts
- replace hand-rolled clamp_cursor_to_char_boundary with str::floor_char_boundary at its four call sites, drop the helper - dedupe the duplicated Layout::vertical constraint arms in render() - drop stale #[allow(dead_code)] on spinner_state (field is read)
This commit is contained in:
@@ -108,10 +108,10 @@ impl MainTui {
|
||||
}
|
||||
|
||||
fn handle_command_bar_input(&mut self, key: KeyEvent) {
|
||||
self.state.command_bar_cursor_position = clamp_cursor_to_char_boundary(
|
||||
&self.state.command_bar_input,
|
||||
self.state.command_bar_cursor_position,
|
||||
);
|
||||
self.state.command_bar_cursor_position = self
|
||||
.state
|
||||
.command_bar_input
|
||||
.floor_char_boundary(self.state.command_bar_cursor_position);
|
||||
|
||||
match key.code {
|
||||
KeyCode::Enter => {
|
||||
@@ -437,23 +437,8 @@ impl MainTui {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) const fn clamp_cursor_to_char_boundary(
|
||||
input: &str,
|
||||
cursor_position: usize,
|
||||
) -> usize {
|
||||
if cursor_position >= input.len() {
|
||||
return input.len();
|
||||
}
|
||||
|
||||
let mut cursor_position = cursor_position;
|
||||
while cursor_position > 0 && !input.is_char_boundary(cursor_position) {
|
||||
cursor_position -= 1;
|
||||
}
|
||||
cursor_position
|
||||
}
|
||||
|
||||
fn previous_char_boundary(input: &str, cursor_position: usize) -> usize {
|
||||
let cursor_position = clamp_cursor_to_char_boundary(input, cursor_position);
|
||||
let cursor_position = input.floor_char_boundary(cursor_position);
|
||||
|
||||
input[..cursor_position]
|
||||
.char_indices()
|
||||
@@ -462,7 +447,7 @@ fn previous_char_boundary(input: &str, cursor_position: usize) -> usize {
|
||||
}
|
||||
|
||||
fn next_char_boundary(input: &str, cursor_position: usize) -> usize {
|
||||
let cursor_position = clamp_cursor_to_char_boundary(input, cursor_position);
|
||||
let cursor_position = input.floor_char_boundary(cursor_position);
|
||||
|
||||
if cursor_position >= input.len() {
|
||||
return input.len();
|
||||
|
||||
@@ -21,7 +21,6 @@ pub struct MainTui {
|
||||
#[allow(dead_code)]
|
||||
max_concurrent_downloads: usize,
|
||||
search_timeout: Duration,
|
||||
#[allow(dead_code)]
|
||||
spinner_state: usize,
|
||||
}
|
||||
|
||||
|
||||
@@ -28,22 +28,15 @@ const fn command_bar_prefix(mode: CommandBarMode) -> &'static str {
|
||||
|
||||
impl MainTui {
|
||||
pub(super) fn render(&mut self, frame: &mut Frame) {
|
||||
let main_chunks = if self.state.command_bar_active {
|
||||
Layout::vertical([
|
||||
Constraint::Length(3), // Status bar
|
||||
Constraint::Fill(1), // Main content
|
||||
Constraint::Length(3), // Command bar
|
||||
Constraint::Length(3), // Shortcuts
|
||||
])
|
||||
.split(frame.area())
|
||||
} else {
|
||||
Layout::vertical([
|
||||
Constraint::Length(3), // Status bar
|
||||
Constraint::Fill(1), // Main content
|
||||
Constraint::Length(3), // Shortcuts
|
||||
])
|
||||
.split(frame.area())
|
||||
};
|
||||
let mut constraints = vec![
|
||||
Constraint::Length(3), // Status bar
|
||||
Constraint::Fill(1), // Main content
|
||||
];
|
||||
if self.state.command_bar_active {
|
||||
constraints.push(Constraint::Length(3)); // Command bar
|
||||
}
|
||||
constraints.push(Constraint::Length(3)); // Shortcuts
|
||||
let main_chunks = Layout::vertical(constraints).split(frame.area());
|
||||
|
||||
render_download_stats(
|
||||
frame,
|
||||
@@ -432,8 +425,7 @@ fn visible_input_at_cursor(
|
||||
return (String::new(), 0);
|
||||
}
|
||||
|
||||
let cursor_position =
|
||||
super::input::clamp_cursor_to_char_boundary(input, cursor_position);
|
||||
let cursor_position = input.floor_char_boundary(cursor_position);
|
||||
let cursor_character_index = input[..cursor_position].chars().count();
|
||||
let max_cursor_column = usize::from(width.saturating_sub(1));
|
||||
let start_character_index =
|
||||
|
||||
Reference in New Issue
Block a user