Skip to content

Commit e0969fc

Browse files
committed
Add $ as a surround character (#8895)
1 parent 79b1d1b commit e0969fc

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

src/actions/motion.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ export class MoveAroundSquareBracket extends MoveInsideCharacter {
20902090
export abstract class MoveQuoteMatch extends BaseMovement {
20912091
override modes = [Mode.Normal, Mode.Visual, Mode.VisualBlock];
20922092
protected readonly anyQuote: boolean = false;
2093-
protected abstract readonly charToMatch: '"' | "'" | '`';
2093+
protected abstract readonly charToMatch: '"' | "'" | '`' | '$';
20942094
protected includeQuotes = false;
20952095
override isJump = true;
20962096
readonly which: WhichQuotes = 'current';
@@ -2232,6 +2232,20 @@ class MoveInsideSingleQuotes extends MoveQuoteMatch {
22322232
override includeQuotes = false;
22332233
}
22342234

2235+
@RegisterAction
2236+
export class MoveInsideDollarSign extends MoveQuoteMatch {
2237+
keys = ['i', '$'];
2238+
readonly charToMatch = '$';
2239+
override includeQuotes = false;
2240+
}
2241+
2242+
@RegisterAction
2243+
export class MoveAroundDollarSign extends MoveQuoteMatch {
2244+
keys = ['a', '$'];
2245+
readonly charToMatch = '$';
2246+
override includeQuotes = true;
2247+
}
2248+
22352249
@RegisterAction
22362250
export class MoveAroundSingleQuotes extends MoveQuoteMatch {
22372251
keys = ['a', "'"];

src/actions/plugins/surround.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
MoveAroundBacktick,
1212
MoveAroundCaret,
1313
MoveAroundCurlyBrace,
14+
MoveAroundDollarSign,
1415
MoveAroundDoubleQuotes,
1516
MoveAroundParentheses,
1617
MoveAroundSingleQuotes,
@@ -499,6 +500,12 @@ class SurroundHelper {
499500
removeSpace: false,
500501
movement: () => new MoveAroundBacktick(false),
501502
},
503+
$: {
504+
left: '$',
505+
right: '$',
506+
removeSpace: true,
507+
movement: () => new MoveAroundDollarSign(false),
508+
},
502509
'<': { left: '', right: '', removeSpace: false, movement: () => new MoveAroundTag() },
503510
'*': {
504511
left: '*',

src/actions/plugins/targets/smartQuotesMatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Position } from 'vscode';
22
import { TextDocument } from 'vscode';
33
import { configuration } from '../../../configuration/configuration';
44

5-
type Quote = '"' | "'" | '`';
5+
type Quote = '"' | "'" | '`' | '$';
66
enum QuoteMatch {
77
Opening,
88
Closing,

src/common/matching/matcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class PairMatcher {
3333
'"': { match: '"', isNextMatchForward: false, directionless: true },
3434
"'": { match: "'", isNextMatchForward: false, directionless: true },
3535
'`': { match: '`', isNextMatchForward: false, directionless: true },
36+
$: { match: '$', isNextMatchForward: false, directionless: true },
3637
};
3738

3839
private static findPairedChar(

src/common/matching/quoteMatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class QuoteMatcher {
1111

1212
private readonly quoteMap: QuoteMatch[] = [];
1313

14-
constructor(quote: '"' | "'" | '`', corpus: string) {
14+
constructor(quote: '"' | "'" | '`' | '$', corpus: string) {
1515
let openingQuote = true;
1616
// Loop over corpus, marking quotes and respecting escape characters.
1717
for (let i = 0; i < corpus.length; i++) {

test/plugins/smartQuotes.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ suite('smartQuotes plugin', () => {
3333
keysPressed: "di'",
3434
end: ['aaa "bbb" c \'|\' '],
3535
});
36+
newTest({
37+
title: 'dollar sign - 1',
38+
start: ['|aaa "bbb" c $d$ '],
39+
keysPressed: "di'",
40+
end: ['aaa "bbb" c $|$ '],
41+
});
42+
newTest({
43+
title: 'dollar sign - 2',
44+
start: ['aaa "bbb" |c $d$ '],
45+
keysPressed: "di'",
46+
end: ['aaa "bbb" c $|$ '],
47+
});
3648
newTest({
3749
title: 'backtick - 1',
3850
start: ['|aaa "bbb" c `d` '],
@@ -63,6 +75,12 @@ suite('smartQuotes plugin', () => {
6375
keysPressed: 'diq',
6476
end: [' \'aaa\' "bbb" c `|` '],
6577
});
78+
newTest({
79+
title: 'any-quote - 4',
80+
start: [' \'aaa\' "bbb" |c $d$ '],
81+
keysPressed: 'diq',
82+
end: [' \'aaa\' "bbb" c $|$ '],
83+
});
6684
// test basic usage
6785
newTest({
6886
title: 'no quotes at all',

0 commit comments

Comments
 (0)