Skip to content

Add $ as a surround character (#8895) #9525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/actions/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ export class MoveAroundSquareBracket extends MoveInsideCharacter {
export abstract class MoveQuoteMatch extends BaseMovement {
override modes = [Mode.Normal, Mode.Visual, Mode.VisualBlock];
protected readonly anyQuote: boolean = false;
protected abstract readonly charToMatch: '"' | "'" | '`';
protected abstract readonly charToMatch: '"' | "'" | '`' | '$';
protected includeQuotes = false;
override isJump = true;
readonly which: WhichQuotes = 'current';
Expand Down Expand Up @@ -2232,6 +2232,20 @@ class MoveInsideSingleQuotes extends MoveQuoteMatch {
override includeQuotes = false;
}

@RegisterAction
export class MoveInsideDollarSign extends MoveQuoteMatch {
keys = ['i', '$'];
readonly charToMatch = '$';
override includeQuotes = false;
}

@RegisterAction
export class MoveAroundDollarSign extends MoveQuoteMatch {
keys = ['a', '$'];
readonly charToMatch = '$';
override includeQuotes = true;
}

@RegisterAction
export class MoveAroundSingleQuotes extends MoveQuoteMatch {
keys = ['a', "'"];
Expand Down
7 changes: 7 additions & 0 deletions src/actions/plugins/surround.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MoveAroundBacktick,
MoveAroundCaret,
MoveAroundCurlyBrace,
MoveAroundDollarSign,
MoveAroundDoubleQuotes,
MoveAroundParentheses,
MoveAroundSingleQuotes,
Expand Down Expand Up @@ -499,6 +500,12 @@ class SurroundHelper {
removeSpace: false,
movement: () => new MoveAroundBacktick(false),
},
$: {
left: '$',
right: '$',
removeSpace: true,
movement: () => new MoveAroundDollarSign(false),
},
'<': { left: '', right: '', removeSpace: false, movement: () => new MoveAroundTag() },
'*': {
left: '*',
Expand Down
2 changes: 1 addition & 1 deletion src/actions/plugins/targets/smartQuotesMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Position } from 'vscode';
import { TextDocument } from 'vscode';
import { configuration } from '../../../configuration/configuration';

type Quote = '"' | "'" | '`';
type Quote = '"' | "'" | '`' | '$';
enum QuoteMatch {
Opening,
Closing,
Expand Down
1 change: 1 addition & 0 deletions src/common/matching/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class PairMatcher {
'"': { match: '"', isNextMatchForward: false, directionless: true },
"'": { match: "'", isNextMatchForward: false, directionless: true },
'`': { match: '`', isNextMatchForward: false, directionless: true },
$: { match: '$', isNextMatchForward: false, directionless: true },
};

private static findPairedChar(
Expand Down
2 changes: 1 addition & 1 deletion src/common/matching/quoteMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class QuoteMatcher {

private readonly quoteMap: QuoteMatch[] = [];

constructor(quote: '"' | "'" | '`', corpus: string) {
constructor(quote: '"' | "'" | '`' | '$', corpus: string) {
let openingQuote = true;
// Loop over corpus, marking quotes and respecting escape characters.
for (let i = 0; i < corpus.length; i++) {
Expand Down
18 changes: 18 additions & 0 deletions test/plugins/smartQuotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ suite('smartQuotes plugin', () => {
keysPressed: "di'",
end: ['aaa "bbb" c \'|\' '],
});
newTest({
title: 'dollar sign - 1',
start: ['|aaa "bbb" c $d$ '],
keysPressed: "di'",
end: ['aaa "bbb" c $|$ '],
});
newTest({
title: 'dollar sign - 2',
start: ['aaa "bbb" |c $d$ '],
keysPressed: "di'",
end: ['aaa "bbb" c $|$ '],
});
newTest({
title: 'backtick - 1',
start: ['|aaa "bbb" c `d` '],
Expand Down Expand Up @@ -63,6 +75,12 @@ suite('smartQuotes plugin', () => {
keysPressed: 'diq',
end: [' \'aaa\' "bbb" c `|` '],
});
newTest({
title: 'any-quote - 4',
start: [' \'aaa\' "bbb" |c $d$ '],
keysPressed: 'diq',
end: [' \'aaa\' "bbb" c $|$ '],
});
// test basic usage
newTest({
title: 'no quotes at all',
Expand Down