Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

vim: Fix change surrounding quotes with whitespace within (#37321)

Dinoc89435154450
diff --git a/crates/vim/src/surrounds.rs b/crates/vim/src/surrounds.rs
index ca65204fab2..83500cf88b5 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]