feat(tui): add Ctrl+←/→ shortcuts to resize files panel

- Update help UI to show “Ctrl+←/→ → resize files panel”.
- Change `set_file_panel_width` to return the clamped width.
- Implement Ctrl+←/→ handling in keyboard input to adjust the files panel width, update status messages, and respect panel collapse state.
This commit is contained in:
2025-10-13 22:14:19 +02:00
parent 23253219a3
commit 3e4eacd1d3
2 changed files with 33 additions and 2 deletions

View File

@@ -1046,10 +1046,12 @@ impl ChatApp {
self.file_panel_width
}
pub fn set_file_panel_width(&mut self, width: u16) {
pub fn set_file_panel_width(&mut self, width: u16) -> u16 {
const MIN_WIDTH: u16 = 24;
const MAX_WIDTH: u16 = 80;
self.file_panel_width = width.clamp(MIN_WIDTH, MAX_WIDTH);
let clamped = width.clamp(MIN_WIDTH, MAX_WIDTH);
self.file_panel_width = clamped;
clamped
}
pub fn expand_file_panel(&mut self) {
@@ -4157,6 +4159,16 @@ impl ChatApp {
let is_symbol_search_key = key.modifiers.contains(KeyModifiers::CONTROL)
&& key.modifiers.contains(KeyModifiers::SHIFT)
&& matches!(key.code, KeyCode::Char('p') | KeyCode::Char('P'));
let is_resize_left = key.modifiers.contains(KeyModifiers::CONTROL)
&& matches!(
key.code,
KeyCode::Left | KeyCode::Char('h') | KeyCode::Char('H')
);
let is_resize_right = key.modifiers.contains(KeyModifiers::CONTROL)
&& matches!(
key.code,
KeyCode::Right | KeyCode::Char('l') | KeyCode::Char('L')
);
if is_reveal_active && matches!(self.mode, InputMode::Normal) {
self.reveal_active_file();
@@ -4179,6 +4191,23 @@ impl ChatApp {
return Ok(AppState::Running);
}
if (is_resize_left || is_resize_right)
&& matches!(self.mode, InputMode::Normal)
&& !self.is_file_panel_collapsed()
{
let current = self.file_panel_width();
let delta: i16 = if is_resize_left { -2 } else { 2 };
let candidate = current.saturating_add_signed(delta);
let adjusted = self.set_file_panel_width(candidate);
if adjusted != current {
self.status = format!("Files panel width: {} cols", adjusted);
self.error = None;
} else {
self.status = "Files panel width unchanged".to_string();
}
return Ok(AppState::Running);
}
if is_symbol_search_key && matches!(self.mode, InputMode::Normal) {
self.set_input_mode(InputMode::SymbolSearch);
self.symbol_search.clear_query();

View File

@@ -3069,6 +3069,7 @@ fn render_help(frame: &mut Frame<'_>, app: &ChatApp) {
Line::from(" F1 / ? → toggle help overlay"),
Line::from(" :h, :help → open help from command mode"),
Line::from(" :files, :explorer → toggle files panel"),
Line::from(" Ctrl+←/→ → resize files panel"),
],
1 => vec![
// Editing
@@ -3181,6 +3182,7 @@ fn render_help(frame: &mut Frame<'_>, app: &ChatApp) {
Line::from(" :h, :help → show this help"),
Line::from(" F1 or ? → toggle help overlay"),
Line::from(" :files, :explorer → toggle files panel"),
Line::from(" Ctrl+←/→ → resize files panel"),
Line::from(" :quit → quit application"),
Line::from(" Ctrl+C twice → quit application"),
Line::from(" :reload → reload configuration and themes"),