Add a setting "use_autoclose" to control autoclose

Also disable autoclose for Chat
This commit is contained in:
Conrad Irwin 2024-01-20 13:32:31 -07:00
parent 72689b08cc
commit 778856c101
4 changed files with 24 additions and 1 deletions

View file

@ -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,

View file

@ -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

View file

@ -408,6 +408,7 @@ pub struct Editor {
style: Option<EditorStyle>,
editor_actions: Vec<Box<dyn Fn(&mut ViewContext<Self>)>>,
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((

View file

@ -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<InlayHintSettings>,
/// 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<bool>,
}
/// 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());