From cb9534eae0d3c373cea5ff4f4e8bb399bc27c972 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 24 Oct 2022 17:46:06 -0700 Subject: [PATCH 1/2] Fix autoclose skipping when start and end are the same character --- crates/editor/src/editor.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 1d660db1fbc1e3910fd38f44bbc3817b1fa2d9b5..387920d81ee20d37b0f49134f01c010e3b102390 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2080,7 +2080,9 @@ impl Editor { )); continue; } - } else if let Some(region) = autoclose_region { + } + + if let Some(region) = autoclose_region { // If the selection is followed by an auto-inserted closing bracket, // then don't insert that closing bracket again; just move the selection // past the closing bracket. From e9073310c4b981641ed7dcc12a854e5d45e9527b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 25 Oct 2022 12:22:19 -0700 Subject: [PATCH 2/2] Add test for autoclosing w/ matching start and end char --- crates/editor/src/editor_tests.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 58978c51f0d388bdcf9a2f0f8700777a34f34311..206b5c67aa34dd382a5fe005d4fdf8c029453311 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -3039,6 +3039,12 @@ async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) { close: false, newline: true, }, + BracketPair { + start: "\"".to_string(), + end: "\"".to_string(), + close: true, + newline: false, + }, ], autoclose_before: "})]".to_string(), ..Default::default() @@ -3159,6 +3165,13 @@ async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) { cx.set_state("«aˇ» b"); cx.update_editor(|view, cx| view.handle_input("{", cx)); cx.assert_editor_state("{«aˇ»} b"); + + // Autclose pair where the start and end characters are the same + cx.set_state("aˇ"); + cx.update_editor(|view, cx| view.handle_input("\"", cx)); + cx.assert_editor_state("a\"ˇ\""); + cx.update_editor(|view, cx| view.handle_input("\"", cx)); + cx.assert_editor_state("a\"\"ˇ"); } #[gpui::test]