language: Add auto-surround for Plain Text, JSON, and JSONC (#42631)

**Summary**
When users selected text and pressed opening brackets (`(`, `[`, `{`),
the text was deleted instead of being wrapped.

- Added bracket pairs: `()`, `[]`, `{}`, `""`, `''` with `surround =
true`
- Added `surround = true` to existing bracket pairs
- Added `()` bracket pair

**Production Build Fix** (`crates/languages/src/lib.rs`)
- Fixed bug where `brackets` config was stripped in non-`load-grammars`
builds
- Preserved `brackets: config.brackets` in production mode

Closes #41186

**Screen recording**

https://github.com/user-attachments/assets/22067fe7-d5c4-4a72-a93d-8dbaae640168

Release Notes:

- N/A *or* Added/Fixed/Improved ...

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
Mustaque Ahmed
2025-12-09 18:27:23 +05:30
committed by GitHub
co-authored by Smit Barmase
parent b79d92d1c6
commit abf90cc274
3 changed files with 48 additions and 6 deletions
+40
View File
@@ -136,6 +136,46 @@ pub static PLAIN_TEXT: LazyLock<Arc<Language>> = LazyLock::new(|| {
path_suffixes: vec!["txt".to_owned()],
first_line_pattern: None,
},
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: true,
surround: true,
newline: false,
},
BracketPair {
start: "[".to_string(),
end: "]".to_string(),
close: true,
surround: true,
newline: false,
},
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
surround: true,
newline: false,
},
BracketPair {
start: "\"".to_string(),
end: "\"".to_string(),
close: true,
surround: true,
newline: false,
},
BracketPair {
start: "'".to_string(),
end: "'".to_string(),
close: true,
surround: true,
newline: false,
},
],
disabled_scopes_by_bracket_ix: Default::default(),
},
..Default::default()
},
None,