Fixes #8872. Fix surround with html tag attribute (#9140)

This commit is contained in:
Peter Kosarnik 2024-08-06 00:23:10 +02:00 committed by GitHub
parent 503788d199
commit af6b0be578
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -654,7 +654,7 @@ class SurroundHelper {
surroundState.operator === 'delete'
? ''
: surroundState.tag
? optNewline + '</' + surroundState.tag.tag + '>'
? optNewline + '</' + SurroundHelper.trimAttributes(surroundState.tag.tag) + '>'
: optNewline + replacement.right;
for (const { leftEdge, rightEdge, cursorIndex } of surroundState.edges) {
@ -680,4 +680,10 @@ class SurroundHelper {
// finish / cleanup. sql-koala was here :D
await vimState.setCurrentMode(Mode.Normal);
}
private static trimAttributes(wholeTag: string) {
const endTagIndex = wholeTag.indexOf(' ');
const isAnyAttributeAfterTag = endTagIndex !== -1;
return isAnyAttributeAfterTag ? wholeTag.substring(0, endTagIndex) : wholeTag;
}
}

View File

@ -507,6 +507,18 @@ suite('surround plugin', () => {
},
});
newTest({
title: "'VStt' surrounds selection and correctly trims class attribute in closing tag",
start: ['first li|ne test'],
keysPressed: 'VStt',
end: ['<div class="test">', 'first line test', '|</div>'],
stub: {
stubClass: CommandSurroundAddSurroundingTag,
methodName: 'readTag',
returnValue: 'div class="test"',
},
});
newTest({
title: "'S)' surrounds visual line selection without space",
start: ['first', 'sec|ond', 'third'],