feat(surround): support complex tags surround

This commit is contained in:
Adam Lee 2017-05-09 20:46:16 -04:00
parent 09b50ab38a
commit dd5e59c4ca
2 changed files with 13 additions and 1 deletions

View File

@ -277,7 +277,12 @@ export class CommandSurroundAddToReplacement extends BaseCommand {
let endReplace = replacement; let endReplace = replacement;
if (startReplace[0] === "<") { if (startReplace[0] === "<") {
endReplace = startReplace[0] + "/" + startReplace.slice(1); let tagName = /([-\w]+)/.exec(startReplace);
if (tagName) {
endReplace = `</${tagName[1]}>`;
} else {
endReplace = "</" + startReplace.slice(1);
}
} }
if (startReplace.length === 1 && startReplace in PairMatcher.pairings) { if (startReplace.length === 1 && startReplace in PairMatcher.pairings) {

View File

@ -33,6 +33,13 @@ suite("surround plugin", () => {
end: ["first <123>|line</123> test"], end: ["first <123>|line</123> test"],
}); });
newTest({
title: "ysiw< surrounds word with tags and attributes",
start: ["first li|ne test"],
keysPressed: 'ysiw<abc attr1 attr2="test">',
end: ['first <abc attr1 attr2="test">|line</abc> test'],
});
newTest({ newTest({
title: "change surround", title: "change surround",
start: ["first 'li|ne' test"], start: ["first 'li|ne' test"],