From 9b3bb0b4aa72ca97789a84a076cad534f1760bca Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 7 Oct 2025 16:35:15 -0400 Subject: [PATCH] Calculate selected navbar entry on each frame based on scrollbar pos This fixes a problem where moving the scrollbar manually wouldn't select the correct sub entry in the navbar or update the navbar at all --- crates/settings_ui/src/settings_ui.rs | 42 ++++++++++++--------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/crates/settings_ui/src/settings_ui.rs b/crates/settings_ui/src/settings_ui.rs index dd08991fec8be96b3d695628ccfa759f039cab45..57b9a0c9ca97820207fe9126959cb362225b1714 100644 --- a/crates/settings_ui/src/settings_ui.rs +++ b/crates/settings_ui/src/settings_ui.rs @@ -1021,9 +1021,7 @@ impl SettingsWindow { window: &mut Window, cx: &mut Context, ) -> impl IntoElement { - let visible_entries: Vec<_> = self.visible_navbar_entries().collect(); - let visible_count = visible_entries.len(); - + let visible_count = self.visible_navbar_entries().count(); let nav_background = cx.theme().colors().panel_background; v_flex() @@ -1193,26 +1191,7 @@ impl SettingsWindow { .size_full() .gap_4() .overflow_y_scroll() - .track_scroll(&self.scroll_handle) - .on_scroll_wheel(cx.listener(move |this, _, _, _| { - let scroll_index = this.scroll_handle.logical_scroll_top().0; - - let mut page_index = this.navbar_entry; - - while !this.navbar_entries[page_index].is_root { - page_index -= 1; - } - - if this.navbar_entries[page_index].expanded { - let section_index = this - .page_items() - .take(scroll_index + 1) - .filter(|item| matches!(item, SettingsPageItem::SectionHeader(_))) - .count(); - - this.navbar_entry = section_index + page_index; - } - })); + .track_scroll(&self.scroll_handle); let items: Vec<_> = items.collect(); let items_len = items.len(); @@ -1387,6 +1366,23 @@ impl Render for SettingsWindow { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { let ui_font = theme::setup_ui_font(window, cx); + let scroll_index = self.scroll_handle.logical_scroll_top().0; + let mut page_index = self.navbar_entry; + + while !self.navbar_entries[page_index].is_root { + page_index -= 1; + } + + if self.navbar_entries[page_index].expanded { + let section_index = self + .page_items() + .take(scroll_index + 1) + .filter(|item| matches!(item, SettingsPageItem::SectionHeader(_))) + .count(); + + self.navbar_entry = section_index + page_index; + } + div() .id("settings-window") .key_context("SettingsWindow")