Ensure settings are being adjusted via settings profile selector (#35382)

This PR just pins down the behavior of the settings profile selector by
checking a single setting, `buffer_font_size`, as options in the
selector are changed / selected.

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-07-30 21:52:02 -04:00 committed by GitHub
parent 67a491df50
commit ed104ec5e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 26 deletions

2
Cargo.lock generated
View file

@ -14709,6 +14709,7 @@ dependencies = [
name = "settings_profile_selector" name = "settings_profile_selector"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"client",
"editor", "editor",
"fuzzy", "fuzzy",
"gpui", "gpui",
@ -14718,6 +14719,7 @@ dependencies = [
"project", "project",
"serde_json", "serde_json",
"settings", "settings",
"theme",
"ui", "ui",
"workspace", "workspace",
"workspace-hack", "workspace-hack",

View file

@ -23,6 +23,7 @@ workspace.workspace = true
zed_actions.workspace = true zed_actions.workspace = true
[dev-dependencies] [dev-dependencies]
client = { workspace = true, features = ["test-support"] }
editor = { workspace = true, features = ["test-support"] } editor = { workspace = true, features = ["test-support"] }
gpui = { workspace = true, features = ["test-support"] } gpui = { workspace = true, features = ["test-support"] }
language = { workspace = true, features = ["test-support"] } language = { workspace = true, features = ["test-support"] }
@ -30,4 +31,5 @@ menu.workspace = true
project = { workspace = true, features = ["test-support"] } project = { workspace = true, features = ["test-support"] }
serde_json.workspace = true serde_json.workspace = true
settings = { workspace = true, features = ["test-support"] } settings = { workspace = true, features = ["test-support"] }
theme = { workspace = true, features = ["test-support"] }
workspace = { workspace = true, features = ["test-support"] } workspace = { workspace = true, features = ["test-support"] }

View file

@ -283,12 +283,15 @@ fn display_name(profile_name: &Option<String>) -> String {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use client;
use editor; use editor;
use gpui::{TestAppContext, UpdateGlobal, VisualTestContext}; use gpui::{TestAppContext, UpdateGlobal, VisualTestContext};
use language; use language;
use menu::{Cancel, Confirm, SelectNext, SelectPrevious}; use menu::{Cancel, Confirm, SelectNext, SelectPrevious};
use project::{FakeFs, Project}; use project::{FakeFs, Project};
use serde_json::json; use serde_json::json;
use settings::Settings;
use theme::{self, ThemeSettings};
use workspace::{self, AppState}; use workspace::{self, AppState};
use zed_actions::settings_profile_selector; use zed_actions::settings_profile_selector;
@ -298,6 +301,12 @@ mod tests {
) -> (Entity<Workspace>, &mut VisualTestContext) { ) -> (Entity<Workspace>, &mut VisualTestContext) {
cx.update(|cx| { cx.update(|cx| {
let state = AppState::test(cx); let state = AppState::test(cx);
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
settings::init(cx);
theme::init(theme::LoadThemes::JustBase, cx);
ThemeSettings::register(cx);
client::init_settings(cx);
language::init(cx); language::init(cx);
super::init(cx); super::init(cx);
editor::init(cx); editor::init(cx);
@ -309,7 +318,8 @@ mod tests {
cx.update(|cx| { cx.update(|cx| {
SettingsStore::update_global(cx, |store, cx| { SettingsStore::update_global(cx, |store, cx| {
let settings_json = json!({ let settings_json = json!({
"profiles": profiles_json "buffer_font_size": 10.0,
"profiles": profiles_json,
}); });
store store
@ -325,6 +335,8 @@ mod tests {
cx.update(|_, cx| { cx.update(|_, cx| {
assert!(!cx.has_global::<ActiveSettingsProfileName>()); assert!(!cx.has_global::<ActiveSettingsProfileName>());
let theme_settings = ThemeSettings::get_global(cx);
assert_eq!(theme_settings.buffer_font_size(cx).0, 10.0);
}); });
(workspace, cx) (workspace, cx)
@ -347,32 +359,37 @@ mod tests {
#[gpui::test] #[gpui::test]
async fn test_settings_profile_selector_state(cx: &mut TestAppContext) { async fn test_settings_profile_selector_state(cx: &mut TestAppContext) {
let demo_videos_profile_name = "Demo Videos".to_string();
let classroom_and_streaming_profile_name = "Classroom / Streaming".to_string();
let profiles_json = json!({ let profiles_json = json!({
"Demo Videos": { demo_videos_profile_name.clone(): {
"buffer_font_size": 14 "buffer_font_size": 15.0
}, },
"Classroom / Streaming": { classroom_and_streaming_profile_name.clone(): {
"buffer_font_size": 16, "buffer_font_size": 20.0,
"vim_mode": true
} }
}); });
let (workspace, cx) = init_test(profiles_json.clone(), cx).await; let (workspace, cx) = init_test(profiles_json.clone(), cx).await;
cx.dispatch_action(settings_profile_selector::Toggle); cx.dispatch_action(settings_profile_selector::Toggle);
let picker = active_settings_profile_picker(&workspace, cx); let picker = active_settings_profile_picker(&workspace, cx);
picker.read_with(cx, |picker, cx| { picker.read_with(cx, |picker, cx| {
assert_eq!(picker.delegate.matches.len(), 3); assert_eq!(picker.delegate.matches.len(), 3);
assert_eq!(picker.delegate.matches[0].string, "Disabled"); assert_eq!(picker.delegate.matches[0].string, display_name(&None));
assert_eq!(picker.delegate.matches[1].string, "Classroom / Streaming"); assert_eq!(
assert_eq!(picker.delegate.matches[2].string, "Demo Videos"); picker.delegate.matches[1].string,
classroom_and_streaming_profile_name
);
assert_eq!(picker.delegate.matches[2].string, demo_videos_profile_name);
assert_eq!(picker.delegate.matches.get(3), None); assert_eq!(picker.delegate.matches.get(3), None);
assert_eq!(picker.delegate.selected_index, 0); assert_eq!(picker.delegate.selected_index, 0);
assert_eq!(picker.delegate.selected_profile_name, None); assert_eq!(picker.delegate.selected_profile_name, None);
assert_eq!(cx.try_global::<ActiveSettingsProfileName>(), None); assert_eq!(cx.try_global::<ActiveSettingsProfileName>(), None);
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0);
}); });
cx.dispatch_action(Confirm); cx.dispatch_action(Confirm);
@ -389,20 +406,23 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 1); assert_eq!(picker.delegate.selected_index, 1);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0);
}); });
cx.dispatch_action(Cancel); cx.dispatch_action(Cancel);
cx.update(|_, cx| { cx.update(|_, cx| {
assert_eq!(cx.try_global::<ActiveSettingsProfileName>(), None); assert_eq!(cx.try_global::<ActiveSettingsProfileName>(), None);
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0);
}); });
cx.dispatch_action(settings_profile_selector::Toggle); cx.dispatch_action(settings_profile_selector::Toggle);
@ -414,14 +434,16 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 1); assert_eq!(picker.delegate.selected_index, 1);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0);
}); });
cx.dispatch_action(SelectNext); cx.dispatch_action(SelectNext);
@ -430,14 +452,16 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 2); assert_eq!(picker.delegate.selected_index, 2);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0);
}); });
cx.dispatch_action(Confirm); cx.dispatch_action(Confirm);
@ -446,8 +470,9 @@ mod tests {
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0);
}); });
cx.dispatch_action(settings_profile_selector::Toggle); cx.dispatch_action(settings_profile_selector::Toggle);
@ -457,14 +482,15 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 2); assert_eq!(picker.delegate.selected_index, 2);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0);
}); });
cx.dispatch_action(SelectPrevious); cx.dispatch_action(SelectPrevious);
@ -473,14 +499,16 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 1); assert_eq!(picker.delegate.selected_index, 1);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0);
}); });
cx.dispatch_action(Cancel); cx.dispatch_action(Cancel);
@ -489,8 +517,10 @@ mod tests {
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0);
}); });
cx.dispatch_action(settings_profile_selector::Toggle); cx.dispatch_action(settings_profile_selector::Toggle);
@ -500,14 +530,16 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 2); assert_eq!(picker.delegate.selected_index, 2);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Demo Videos".to_string()) Some(demo_videos_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Demo Videos".to_string()) Some(demo_videos_profile_name)
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0);
}); });
cx.dispatch_action(SelectPrevious); cx.dispatch_action(SelectPrevious);
@ -516,14 +548,16 @@ mod tests {
assert_eq!(picker.delegate.selected_index, 1); assert_eq!(picker.delegate.selected_index, 1);
assert_eq!( assert_eq!(
picker.delegate.selected_profile_name, picker.delegate.selected_profile_name,
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name.clone())
); );
assert_eq!( assert_eq!(
cx.try_global::<ActiveSettingsProfileName>() cx.try_global::<ActiveSettingsProfileName>()
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
Some("Classroom / Streaming".to_string()) Some(classroom_and_streaming_profile_name)
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0);
}); });
cx.dispatch_action(SelectPrevious); cx.dispatch_action(SelectPrevious);
@ -537,12 +571,15 @@ mod tests {
.map(|p| p.0.clone()), .map(|p| p.0.clone()),
None None
); );
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0);
}); });
cx.dispatch_action(Confirm); cx.dispatch_action(Confirm);
cx.update(|_, cx| { cx.update(|_, cx| {
assert_eq!(cx.try_global::<ActiveSettingsProfileName>(), None); assert_eq!(cx.try_global::<ActiveSettingsProfileName>(), None);
assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0);
}); });
} }
} }