1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-07-31 03:59:07 +02:00

Strip tag attributes from closing tag for Vim-Surround

This commit is contained in:
Tony Arra 2019-01-21 09:02:39 -05:00
parent 95f56a8869
commit 63be2c28e9
2 changed files with 14 additions and 3 deletions
src/com/maddyhome/idea/vim/extension/surround
test/org/jetbrains/plugins/ideavim/extension/surround

View File

@ -43,6 +43,7 @@ import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.*;
import static com.maddyhome.idea.vim.extension.VimExtensionFacade.*;
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
@ -109,9 +110,13 @@ public class VimSurroundExtension extends VimNonDisposableExtension {
@Nullable
private static Pair<String, String> inputTagPair(@NotNull Editor editor) {
final String tagInput = inputString(editor, "<");
if (tagInput.endsWith(">")) {
final String tagName = tagInput.substring(0, tagInput.length() - 1);
return Pair.create("<" + tagName + ">", "</" + tagName + ">");
final Pattern tagNameAndAttributesCapturePattern = Pattern.compile("(\\w+)([^>]*)>");
final Matcher matcher = tagNameAndAttributesCapturePattern.matcher(tagInput);
if (matcher.find()) {
final String tagName = matcher.group(1);
final String tagAttributes = matcher.group(2);
return Pair.create("<" + tagName + tagAttributes + ">", "</" + tagName + ">");
}
else {
return null;

View File

@ -82,6 +82,12 @@ public class VimSurroundExtensionTest extends VimTestCase {
myFixture.checkResult("Hello <em>World</em>!\n");
}
public void testSurroundTagWithAttributes() {
configureByText("Hello <caret>World!");
typeText(parseKeys("ysiw\\<span class=\"important\" data-foo=\"bar\">"));
myFixture.checkResult("Hello <span class=\"important\" data-foo=\"bar\">World</span>!");
}
/* visual surround */
public void testVisualSurroundWordParens() {