Merge pull request #1714 from zed-industries/fix-autoclose
Don't autoclose brackets when `close` is false
This commit is contained in:
commit
7528bf8f32
2 changed files with 12 additions and 1 deletions
|
@ -1874,7 +1874,7 @@ impl Editor {
|
||||||
let mut bracket_pair = None;
|
let mut bracket_pair = None;
|
||||||
let mut is_bracket_pair_start = false;
|
let mut is_bracket_pair_start = false;
|
||||||
for pair in language.brackets() {
|
for pair in language.brackets() {
|
||||||
if pair.start.ends_with(text.as_ref()) {
|
if pair.close && pair.start.ends_with(text.as_ref()) {
|
||||||
bracket_pair = Some(pair.clone());
|
bracket_pair = Some(pair.clone());
|
||||||
is_bracket_pair_start = true;
|
is_bracket_pair_start = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3016,6 +3016,11 @@ async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) {
|
||||||
cx.update_editor(|view, cx| view.handle_input("{", cx));
|
cx.update_editor(|view, cx| view.handle_input("{", cx));
|
||||||
cx.assert_editor_state("{ˇa b");
|
cx.assert_editor_state("{ˇa b");
|
||||||
|
|
||||||
|
// Don't autoclose if `close` is false for the bracket pair
|
||||||
|
cx.set_state("ˇ");
|
||||||
|
cx.update_editor(|view, cx| view.handle_input("[", cx));
|
||||||
|
cx.assert_editor_state("[ˇ");
|
||||||
|
|
||||||
// Surround with brackets if text is selected
|
// Surround with brackets if text is selected
|
||||||
cx.set_state("«aˇ» b");
|
cx.set_state("«aˇ» b");
|
||||||
cx.update_editor(|view, cx| view.handle_input("{", cx));
|
cx.update_editor(|view, cx| view.handle_input("{", cx));
|
||||||
|
@ -3034,16 +3039,19 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) {
|
||||||
BracketPair {
|
BracketPair {
|
||||||
start: "<".into(),
|
start: "<".into(),
|
||||||
end: ">".into(),
|
end: ">".into(),
|
||||||
|
close: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
BracketPair {
|
BracketPair {
|
||||||
start: "{".into(),
|
start: "{".into(),
|
||||||
end: "}".into(),
|
end: "}".into(),
|
||||||
|
close: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
BracketPair {
|
BracketPair {
|
||||||
start: "(".into(),
|
start: "(".into(),
|
||||||
end: ")".into(),
|
end: ")".into(),
|
||||||
|
close: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -3069,16 +3077,19 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) {
|
||||||
BracketPair {
|
BracketPair {
|
||||||
start: "/*".into(),
|
start: "/*".into(),
|
||||||
end: " */".into(),
|
end: " */".into(),
|
||||||
|
close: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
BracketPair {
|
BracketPair {
|
||||||
start: "{".into(),
|
start: "{".into(),
|
||||||
end: "}".into(),
|
end: "}".into(),
|
||||||
|
close: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
BracketPair {
|
BracketPair {
|
||||||
start: "(".into(),
|
start: "(".into(),
|
||||||
end: ")".into(),
|
end: ")".into(),
|
||||||
|
close: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue