diff --git a/crates/vim/src/surrounds.rs b/crates/vim/src/surrounds.rs index ca65204fab2a8ddd21e4788ca5c1e5cbe325447c..83500cf88b56c8f556887eb874901f50b6178018 100644 --- a/crates/vim/src/surrounds.rs +++ b/crates/vim/src/surrounds.rs @@ -240,7 +240,24 @@ impl Vim { newline: false, }, }; - let surround = pair.end != surround_alias((*text).as_ref()); + + // Determines whether space should be added/removed after + // and before the surround pairs. + // For example, using `cs{[` will add a space before and + // after the pair, while using `cs{]` will not, notice the + // use of the closing bracket instead of the opening bracket + // on the target object. + // In the case of quotes, the opening and closing is the + // same, so no space will ever be added or removed. + let surround = match target { + Object::Quotes + | Object::BackQuotes + | Object::AnyQuotes + | Object::MiniQuotes + | Object::DoubleQuotes => true, + _ => pair.end != surround_alias((*text).as_ref()), + }; + let (display_map, selections) = editor.selections.all_adjusted_display(cx); let mut edits = Vec::new(); let mut anchors = Vec::new(); @@ -1128,6 +1145,30 @@ mod test { ];"}, Mode::Normal, ); + + // test change quotes. + cx.set_state(indoc! {"' ˇstr '"}, Mode::Normal); + cx.simulate_keystrokes("c s ' \""); + cx.assert_state(indoc! {"ˇ\" str \""}, Mode::Normal); + + // test multi cursor change quotes + cx.set_state( + indoc! {" + ' ˇstr ' + some example text here + ˇ' str ' + "}, + Mode::Normal, + ); + cx.simulate_keystrokes("c s ' \""); + cx.assert_state( + indoc! {" + ˇ\" str \" + some example text here + ˇ\" str \" + "}, + Mode::Normal, + ); } #[gpui::test]