Skip to content

Commit 58f625e

Browse files
authored
Fix change surrounding tag, fixes #8177 (#9648)
1 parent e819f6f commit 58f625e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/actions/plugins/surround.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SelectWord,
77
TextObject,
88
} from '../../textobject/textobject';
9+
import { WordType } from '../../textobject/word';
910
import { isIMovement } from '../baseMotion';
1011
import {
1112
MoveAroundBacktick,
@@ -585,11 +586,11 @@ class SurroundHelper {
585586
// start -> <foo>bar</foo> <-- stop
586587
const openTagNameStart = rangeStart.getRight();
587588
const openTagNameEnd = openTagNameStart
588-
.nextWordEnd(vimState.document, { inclusive: true })
589+
.nextWordEnd(vimState.document, { wordType: WordType.TagName, inclusive: true })
589590
.getRight();
590591
const closeTagNameStart = rangeEnd
591592
.getLeft(2)
592-
.prevWordStart(vimState.document, { inclusive: true });
593+
.prevWordStart(vimState.document, { wordType: WordType.TagName, inclusive: true });
593594
const closeTagNameEnd = rangeEnd.getLeft();
594595
vimState.cursorStartPosition = position; // some textobj (MoveInsideCharacter) expect this
595596
vimState.cursorStopPosition = position;

src/textobject/word.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export enum WordType {
88
Big,
99
CamelCase,
1010
FileName,
11+
TagName,
1112
}
1213

1314
const nonBigWordCharRegex = makeWordRegex('');
1415
const nonFileNameRegex = makeWordRegex('"\'`;<>{}[]()');
16+
const nonTagNameRegex = makeWordRegex('</>');
1517

1618
function regexForWordType(wordType: WordType): RegExp {
1719
switch (wordType) {
@@ -23,6 +25,8 @@ function regexForWordType(wordType: WordType): RegExp {
2325
return makeCamelCaseWordRegex(configuration.iskeyword);
2426
case WordType.FileName:
2527
return nonFileNameRegex;
28+
case WordType.TagName:
29+
return nonTagNameRegex;
2630
}
2731
}
2832

test/plugins/surround.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,18 @@ suite('surround plugin', () => {
456456
},
457457
});
458458

459+
newTest({
460+
title: 'change surround with tags with kebab case names',
461+
start: ['<custom-tag>|</custom-tag>'],
462+
keysPressed: 'cstt',
463+
end: ['<h1>|</h1>'],
464+
stub: {
465+
stubClass: CommandSurroundAddSurroundingTag,
466+
methodName: 'readTag',
467+
returnValue: 'h1',
468+
},
469+
});
470+
459471
newTest({
460472
title: 'change surround with tags that contain an attribute and remove them',
461473
start: ['<h2 test class="foo">b|ar</h2>'],

0 commit comments

Comments
 (0)