diff --git a/CHANGELOG.md b/CHANGELOG.md index c44c9c73..04caaf7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#1475](https://github.com/lapce/lapce/pull/1475): Add editor setting: "Cursor Surrounding Lines" which sets minimum number of lines above and below cursor - [#1525](https://github.com/lapce/lapce/pull/1525): Add editor indent guide - [#1521](https://github.com/lapce/lapce/pull/1521): Show unique paths to disambiguate same file names +- [#1452](https://github.com/lapce/lapce/pull/1452): Wrap selected text with brackets/quotes ### Bug Fixes diff --git a/lapce-core/src/editor.rs b/lapce-core/src/editor.rs index 0d691874..fafa7901 100644 --- a/lapce-core/src/editor.rs +++ b/lapce-core/src/editor.rs @@ -93,9 +93,10 @@ pub fn insert( // when text is selected, and [,{,(,'," is inserted // wrap the text with that char and its corresponding closing pair - if region.start != region.end && matching_pair_type == Some(true) - || c == '"' - || c == '\'' + if region.start != region.end + && (matching_pair_type == Some(true) + || c == '"' + || c == '\'') { edits.push(( Selection::region(region.min(), region.min()), @@ -1494,6 +1495,17 @@ fn test_insert_pair() { assert_eq!("a{} bc\ne{} fg\n", buffer.slice_to_cow(0..buffer.len())); } + #[test] + fn test_insert_pair_with_selection() { + let mut buffer = Buffer::new("a bc\ne fg\n"); + let mut selection = Selection::new(); + selection.add_region(SelRegion::new(0, 4, None)); + selection.add_region(SelRegion::new(5, 9, None)); + let mut cursor = Cursor::new(CursorMode::Insert(selection), None, None); + Editor::insert(&mut cursor, &mut buffer, "{", None, true); + assert_eq!("{a bc}\n{e fg}\n", buffer.slice_to_cow(0..buffer.len())); + } + #[test] fn test_insert_pair_without_auto_closing() { let mut buffer = Buffer::new("a bc\ne fg\n");