fix(settings_ui): fix scrollbar breaking when ui font size changes
dino
created
When the UI font size changes, the settings window's scrollbar would
break because list item measurements were cached and not invalidated.
We're using `ListState.measure_all()` to pre-measure all items for an
accurate scrollbar. When font size changes, these cached measurements
become stale but weren't being refreshed.
This commit fixes the issue by calling `ListState.measure_all()` when
settings change, ensuring items are re-measured on the next layout
without affecting scroll position.
Closes #43683
@@ -1378,6 +1378,14 @@ impl SettingsWindow {
cx.observe_global_in::<SettingsStore>(window, move |this, window, cx| {
this.fetch_files(window, cx);
+
+ // Whenever settings are changed, it's possible that the changed
+ // settings affects the rendering of the `SettingsWindow`, like is
+ // the case with `ui_font_size`. When that happens, we need to
+ // instruct the `ListState` to re-measure the list items, as the
+ // list item heights may have changed depending on the new font
+ // size.
+ this.list_state.clone().measure_all();
cx.notify();
})
.detach();
@@ -1487,7 +1495,6 @@ impl SettingsWindow {
None
};
- // high overdraw value so the list scrollbar len doesn't change too much
let list_state = gpui::ListState::new(0, gpui::ListAlignment::Top, px(0.0)).measure_all();
list_state.set_scroll_handler(|_, _, _| {});
@@ -1980,7 +1987,6 @@ impl SettingsWindow {
}
fn reset_list_state(&mut self) {
- // plus one for the title
let mut visible_items_count = self.visible_page_items().count();
if visible_items_count > 0 {