Merge pull request #1802 from zed-industries/autoclose-with-same-start-and-end

Fix autoclose skipping when start and end are the same character
This commit is contained in:
Max Brunsfeld 2022-10-25 12:33:04 -07:00 committed by GitHub
commit 6a2dc444c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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.

View File

@ -3041,6 +3041,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()
@ -3161,6 +3167,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("");
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]