From 3ae96f2c6eb0612a6d0ec4729da64ff2f7260a15 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 10 Oct 2022 15:15:43 -0600 Subject: [PATCH 1/2] Don't autoclose brackets when is false --- crates/editor/src/editor.rs | 2 +- crates/editor/src/editor_tests.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 38ca82b0d2..d1dfed3c85 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1874,7 +1874,7 @@ impl Editor { let mut bracket_pair = None; let mut is_bracket_pair_start = false; 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()); is_bracket_pair_start = true; break; diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 430b958407..3525fa4676 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -3016,6 +3016,11 @@ async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) { cx.update_editor(|view, cx| view.handle_input("{", cx)); 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 cx.set_state("«aˇ» b"); cx.update_editor(|view, cx| view.handle_input("{", cx)); From 425e540c9a236ba495e25b2de527a5fe0ffae4a4 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 10 Oct 2022 15:29:24 -0600 Subject: [PATCH 2/2] Fix tests by providing close: true --- crates/editor/src/editor_tests.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 3525fa4676..063dcf6098 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -3039,16 +3039,19 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) { BracketPair { start: "<".into(), end: ">".into(), + close: true, ..Default::default() }, BracketPair { start: "{".into(), end: "}".into(), + close: true, ..Default::default() }, BracketPair { start: "(".into(), end: ")".into(), + close: true, ..Default::default() }, ], @@ -3074,16 +3077,19 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) { BracketPair { start: "/*".into(), end: " */".into(), + close: true, ..Default::default() }, BracketPair { start: "{".into(), end: "}".into(), + close: true, ..Default::default() }, BracketPair { start: "(".into(), end: ")".into(), + close: true, ..Default::default() }, ],