vim: Fix regression in surround behavior (#38344)
Fix an issue introduced in https://github.com/zed-industries/zed/pull/37321 where vim's surround wouldn't work as expected when replacing quotes with non-quotes, with whitespace always being added, regardless of whether the opening or closing bracket was used. This is not the intended, or previous, behavior, where only the opening bracket would trigger whitespace to be added. Closes #38169 Release Notes: - Fixed regression in vim's surround plugin that ignored whether the opening or closing bracket was being used when replacing quotes, so space would always be added
This commit is contained in:
+17
-14
@@ -241,21 +241,15 @@ impl Vim {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Determines whether space should be added/removed after
|
// Determines whether space should be added after
|
||||||
// and before the surround pairs.
|
// and before the surround pairs.
|
||||||
// For example, using `cs{[` will add a space before and
|
// Space is only added in the following cases:
|
||||||
// after the pair, while using `cs{]` will not, notice the
|
// - new surround is not quote and is opening bracket (({[<)
|
||||||
// use of the closing bracket instead of the opening bracket
|
// - new surround is quote and original was also quote
|
||||||
// on the target object.
|
let surround = if pair.start != pair.end {
|
||||||
// In the case of quotes, the opening and closing is the
|
pair.end != surround_alias((*text).as_ref())
|
||||||
// same, so no space will ever be added or removed.
|
} else {
|
||||||
let surround = match target {
|
will_replace_pair.start == will_replace_pair.end
|
||||||
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 (display_map, selections) = editor.selections.all_adjusted_display(cx);
|
||||||
@@ -1241,6 +1235,15 @@ mod test {
|
|||||||
"},
|
"},
|
||||||
Mode::Normal,
|
Mode::Normal,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// test quote to bracket spacing.
|
||||||
|
cx.set_state(indoc! {"'ˇfoobar'"}, Mode::Normal);
|
||||||
|
cx.simulate_keystrokes("c s ' {");
|
||||||
|
cx.assert_state(indoc! {"ˇ{ foobar }"}, Mode::Normal);
|
||||||
|
|
||||||
|
cx.set_state(indoc! {"'ˇfoobar'"}, Mode::Normal);
|
||||||
|
cx.simulate_keystrokes("c s ' }");
|
||||||
|
cx.assert_state(indoc! {"ˇ{foobar}"}, Mode::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user