tab: Add setting to hide the close button entirely (#23880)

Closes #23744

Release Notes:

- Changed the `always_show_close_button` key to `show_close_button` and
introduced a new `hidden` value, that allows never displaying the close
button.

---------

Co-authored-by: Peter Tripp <peter@zed.dev>
Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
Co-authored-by: smit <0xtimsb@gmail.com>
This commit is contained in:
Morgan Metz 2025-03-02 19:01:48 -08:00 committed by GitHub
parent ae6d350334
commit 0a4ff2f475
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 149 additions and 28 deletions

View file

@ -72,7 +72,7 @@ pub fn migrate_edit_prediction_provider_settings(text: &str) -> Result<Option<St
migrate(
&text,
&[(
SETTINGS_REPLACE_NESTED_KEY,
SETTINGS_NESTED_KEY_VALUE_PATTERN,
replace_edit_prediction_provider_setting,
)],
&EDIT_PREDICTION_SETTINGS_MIGRATION_QUERY,
@ -571,9 +571,17 @@ pub static ACTION_ARGUMENT_SNAKE_CASE_REPLACE: LazyLock<HashMap<&str, &str>> =
const SETTINGS_MIGRATION_PATTERNS: MigrationPatterns = &[
(SETTINGS_STRING_REPLACE_QUERY, replace_setting_name),
(
SETTINGS_REPLACE_NESTED_KEY,
SETTINGS_NESTED_KEY_VALUE_PATTERN,
replace_edit_prediction_provider_setting,
),
(
SETTINGS_NESTED_KEY_VALUE_PATTERN,
replace_tab_close_button_setting_key,
),
(
SETTINGS_NESTED_KEY_VALUE_PATTERN,
replace_tab_close_button_setting_value,
),
(
SETTINGS_REPLACE_IN_LANGUAGES_QUERY,
replace_setting_in_languages,
@ -594,7 +602,7 @@ static SETTINGS_MIGRATION_QUERY: LazyLock<Query> = LazyLock::new(|| {
static EDIT_PREDICTION_SETTINGS_MIGRATION_QUERY: LazyLock<Query> = LazyLock::new(|| {
Query::new(
&tree_sitter_json::LANGUAGE.into(),
SETTINGS_REPLACE_NESTED_KEY,
SETTINGS_NESTED_KEY_VALUE_PATTERN,
)
.unwrap()
});
@ -639,14 +647,14 @@ pub static SETTINGS_STRING_REPLACE: LazyLock<HashMap<&'static str, &'static str>
])
});
const SETTINGS_REPLACE_NESTED_KEY: &str = r#"
const SETTINGS_NESTED_KEY_VALUE_PATTERN: &str = r#"
(object
(pair
key: (string (string_content) @parent_key)
value: (object
(pair
key: (string (string_content) @setting_name)
value: (_) @value
value: (_) @setting_value
)
)
)
@ -679,6 +687,73 @@ fn replace_edit_prediction_provider_setting(
None
}
fn replace_tab_close_button_setting_key(
contents: &str,
mat: &QueryMatch,
query: &Query,
) -> Option<(Range<usize>, String)> {
let parent_object_capture_ix = query.capture_index_for_name("parent_key")?;
let parent_object_range = mat
.nodes_for_capture_index(parent_object_capture_ix)
.next()?
.byte_range();
let parent_object_name = contents.get(parent_object_range.clone())?;
let setting_name_ix = query.capture_index_for_name("setting_name")?;
let setting_range = mat
.nodes_for_capture_index(setting_name_ix)
.next()?
.byte_range();
let setting_name = contents.get(setting_range.clone())?;
if parent_object_name == "tabs" && setting_name == "always_show_close_button" {
return Some((setting_range, "show_close_button".into()));
}
None
}
fn replace_tab_close_button_setting_value(
contents: &str,
mat: &QueryMatch,
query: &Query,
) -> Option<(Range<usize>, String)> {
let parent_object_capture_ix = query.capture_index_for_name("parent_key")?;
let parent_object_range = mat
.nodes_for_capture_index(parent_object_capture_ix)
.next()?
.byte_range();
let parent_object_name = contents.get(parent_object_range.clone())?;
let setting_name_ix = query.capture_index_for_name("setting_name")?;
let setting_name_range = mat
.nodes_for_capture_index(setting_name_ix)
.next()?
.byte_range();
let setting_name = contents.get(setting_name_range.clone())?;
let setting_value_ix = query.capture_index_for_name("setting_value")?;
let setting_value_range = mat
.nodes_for_capture_index(setting_value_ix)
.next()?
.byte_range();
let setting_value = contents.get(setting_value_range.clone())?;
if parent_object_name == "tabs" && setting_name == "always_show_close_button" {
match setting_value {
"true" => {
return Some((setting_value_range, "\"always\"".to_string()));
}
"false" => {
return Some((setting_value_range, "\"hover\"".to_string()));
}
_ => {}
}
}
None
}
const SETTINGS_REPLACE_IN_LANGUAGES_QUERY: &str = r#"
(object
(pair