diff --git a/assets/settings/default.json b/assets/settings/default.json index 87cf0517a2..a920a9c68a 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -72,6 +72,9 @@ // Whether to use additional LSP queries to format (and amend) the code after // every "trigger" symbol input, defined by LSP server capabilities. "use_on_type_format": true, + // Whether to automatically type closing characters for you. For example, + // when you type (, Zed will automatically add a closing ) at the correct position. + "use_autoclose": true, // Controls whether copilot provides suggestion immediately // or waits for a `copilot::Toggle` "show_copilot_suggestions": true, diff --git a/crates/collab_ui/src/chat_panel/message_editor.rs b/crates/collab_ui/src/chat_panel/message_editor.rs index 43b432cfb2..41d2c26f49 100644 --- a/crates/collab_ui/src/chat_panel/message_editor.rs +++ b/crates/collab_ui/src/chat_panel/message_editor.rs @@ -40,6 +40,7 @@ impl MessageEditor { ) -> Self { editor.update(cx, |editor, cx| { editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); + editor.set_use_autoclose(false); }); let buffer = editor diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b31dd54208..e6a27bc109 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -408,6 +408,7 @@ pub struct Editor { style: Option, editor_actions: Vec)>>, show_copilot_suggestions: bool, + use_autoclose: bool, } pub struct EditorSnapshot { @@ -1603,6 +1604,7 @@ impl Editor { keymap_context_layers: Default::default(), input_enabled: true, read_only: false, + use_autoclose: true, leader_peer_id: None, remote_id: None, hover_state: Default::default(), @@ -1880,6 +1882,10 @@ impl Editor { self.read_only = read_only; } + pub fn set_use_autoclose(&mut self, autoclose: bool) { + self.use_autoclose = autoclose; + } + pub fn set_show_copilot_suggestions(&mut self, show_copilot_suggestions: bool) { self.show_copilot_suggestions = show_copilot_suggestions; } @@ -2478,7 +2484,12 @@ impl Editor { ), &bracket_pair.start[..prefix_len], )); - if following_text_allows_autoclose && preceding_text_matches_prefix { + let autoclose = self.use_autoclose + && snapshot.settings_at(selection.start, cx).use_autoclose; + if autoclose + && following_text_allows_autoclose + && preceding_text_matches_prefix + { let anchor = snapshot.anchor_before(selection.end); new_selections.push((selection.map(|_| anchor), text.len())); new_autoclose_regions.push(( diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 292e2ad9dc..cdd96ad6ab 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -91,6 +91,8 @@ pub struct LanguageSettings { pub extend_comment_on_newline: bool, /// Inlay hint related settings. pub inlay_hints: InlayHintSettings, + /// Whether to automatically close brackets. + pub use_autoclose: bool, } /// The settings for [GitHub Copilot](https://github.com/features/copilot). @@ -208,6 +210,11 @@ pub struct LanguageSettingsContent { /// Inlay hint related settings. #[serde(default)] pub inlay_hints: Option, + /// Whether to automatically type closing characters for you. For example, + /// when you type (, Zed will automatically add a closing ) at the correct position. + /// + /// Default: true + pub use_autoclose: Option, } /// The contents of the GitHub Copilot settings. @@ -540,6 +547,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent merge(&mut settings.tab_size, src.tab_size); merge(&mut settings.hard_tabs, src.hard_tabs); merge(&mut settings.soft_wrap, src.soft_wrap); + merge(&mut settings.use_autoclose, src.use_autoclose); merge(&mut settings.show_wrap_guides, src.show_wrap_guides); merge(&mut settings.wrap_guides, src.wrap_guides.clone());