Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

language: Autoclose nested brackets in plain text (#60841)

Apoorva Verma869d6eae2277
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index 2a4ac54cf59..43b30c471a2 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -27,7 +27,7 @@ use language::{
Capability::ReadWrite,
ContextLocation, ContextProvider, DiagnosticSourceKind, FakeLspAdapter, IndentGuideSettings,
LanguageConfig, LanguageConfigOverride, LanguageMatcher, LanguageName, LanguageQueries,
- LanguageToolchainStore, Override, Point,
+ LanguageToolchainStore, Override, PLAIN_TEXT, Point,
language_settings::{
CompletionSettingsContent, FormatOnSave, FormatterList, LanguageSettingsContent,
LspInsertMode,
@@ -12955,6 +12955,29 @@ async fn test_autoindent_selections(cx: &mut TestAppContext) {
}
}
+#[gpui::test]
+async fn test_autoclose_nested_brackets_in_plain_text(cx: &mut TestAppContext) {
+ init_test(cx, |_| {});
+ let mut cx = EditorTestContext::new(cx).await;
+
+ let language = PLAIN_TEXT.clone();
+ cx.language_registry().add(language.clone());
+ cx.update_buffer(|buffer, cx| {
+ buffer.set_language(Some(language), cx);
+ });
+
+ cx.set_state("ˇ");
+
+ // Typing an opening bracket right before an existing closing bracket should
+ // still autoclose, not skip because the following char is `)`.
+ cx.update_editor(|editor, window, cx| {
+ editor.handle_input("(", window, cx);
+ editor.handle_input("[", window, cx);
+ editor.handle_input("{", window, cx);
+ });
+ cx.assert_editor_state("([{ˇ}])");
+}
+
#[gpui::test]
async fn test_autoclose_and_auto_surround_pairs(cx: &mut TestAppContext) {
init_test(cx, |_| {});
diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs
index 6a799b62d32..f15b241b296 100644
--- a/crates/language/src/language.rs
+++ b/crates/language/src/language.rs
@@ -164,6 +164,7 @@ pub static PLAIN_TEXT: LazyLock<Arc<Language>> = LazyLock::new(|| {
LanguageConfig {
name: "Plain Text".into(),
soft_wrap: Some(SoftWrap::EditorWidth),
+ autoclose_before: ")]}".into(),
matcher: LanguageMatcher {
path_suffixes: vec!["txt".to_owned()],
first_line_pattern: None,