mirror of
https://github.com/forkless/NotAlterra.git
synced 2026-08-20 18:18:57 +02:00
fix state offset for pinned header lists, fix Enter index in restore backup
This commit is contained in:
+2
-1
@@ -971,7 +971,8 @@ fn action_restore_backup<B: Backend>(terminal: &mut Terminal<B>, app: &mut App)
|
||||
state.select(Some((i + 1).min(backups.len().saturating_sub(1))));
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
let idx = state.selected().unwrap_or(0);
|
||||
let idx = state.selected().unwrap_or(2).max(2).saturating_sub(2);
|
||||
if idx >= backups.len() { continue; }
|
||||
let chosen = &backups[idx];
|
||||
let name = chosen.file_name().unwrap().to_string_lossy().to_string();
|
||||
|
||||
|
||||
+19
-3
@@ -836,6 +836,17 @@ fn draw_select_list_with_info(
|
||||
..area
|
||||
};
|
||||
|
||||
// Offset: when pinned_header is true, the list widget only sees
|
||||
// items[2..], but state.selected() is absolute to the full items array.
|
||||
// Adjust the state so the list widget highlights the correct entry.
|
||||
let header_offset = if pinned_header && !items.is_empty() { 2u16 } else { 0u16 };
|
||||
let orig_selected = state.selected();
|
||||
if header_offset > 0 {
|
||||
if let Some(s) = orig_selected {
|
||||
state.select(Some(s.saturating_sub(header_offset as usize)));
|
||||
}
|
||||
}
|
||||
|
||||
let list_items: Vec<ListItem> = list_items_slice
|
||||
.iter()
|
||||
.map(|item| ListItem::new(Span::raw(*item)).style(Style::default()))
|
||||
@@ -852,10 +863,15 @@ fn draw_select_list_with_info(
|
||||
|
||||
f.render_stateful_widget(list, list_area, state);
|
||||
|
||||
// Description line for the highlighted item
|
||||
// Restore state to absolute indexing for the caller
|
||||
if header_offset > 0 {
|
||||
let s = state.selected().unwrap_or(0);
|
||||
state.select(Some(s + header_offset as usize));
|
||||
}
|
||||
|
||||
// Description line — use original (absolute) selection index
|
||||
let base_y = area.y + area.height.saturating_sub(1);
|
||||
let desc_idx = state
|
||||
.selected()
|
||||
let desc_idx = orig_selected
|
||||
.unwrap_or(0)
|
||||
.min(descs.len().saturating_sub(1));
|
||||
let desc = descs.get(desc_idx).copied().unwrap_or("");
|
||||
|
||||
Reference in New Issue
Block a user