Fix host navigation to work with alphabetical host ordering

- Fix host_index calculation for localhost to use actual position in sorted list
- Remove incorrect assumption that localhost is always at index 0
- Host navigation (Tab key) now works correctly with all hosts in alphabetical order

Fixes issue where only 3 of 5 hosts were accessible via Tab navigation.
This commit is contained in:
Christoffer Martinsson 2025-10-20 13:12:39 +02:00
parent d349e2742d
commit 959745b51b

View File

@ -146,8 +146,9 @@ impl TuiApp {
if !self.available_hosts.is_empty() { if !self.available_hosts.is_empty() {
if self.available_hosts.contains(&localhost) && !self.user_navigated_away { if self.available_hosts.contains(&localhost) && !self.user_navigated_away {
// Localhost is available and user hasn't navigated away - switch to it // Localhost is available and user hasn't navigated away - switch to it
self.current_host = Some(localhost); self.current_host = Some(localhost.clone());
self.host_index = 0; // localhost is always first in sorted_hosts // Find the actual index of localhost in the sorted list
self.host_index = self.available_hosts.iter().position(|h| h == &localhost).unwrap_or(0);
} else if self.current_host.is_none() { } else if self.current_host.is_none() {
// No current host - select first available (which is localhost if available) // No current host - select first available (which is localhost if available)
self.current_host = Some(self.available_hosts[0].clone()); self.current_host = Some(self.available_hosts[0].clone());