Skip to content

Commit

Permalink
Fix f/F/t/T with <tab> (VSCodeVim#3914)
Browse files Browse the repository at this point in the history
* Fix f/F/t/T with <tab>

Fixes VSCodeVim#2510

* Code review: use helper function
  • Loading branch information
J-Fields authored and stevenguh committed Aug 27, 2019
1 parent d1febb7 commit cb3a9fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/actions/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { configuration } from './../configuration/configuration';
import { shouldWrapKey } from './wrapping';
import { VimError, ErrorCode } from '../error';
import { ReportSearch } from '../util/statusBarTextUtils';
import { Notation } from '../configuration/notation';

export function isIMovement(o: IMovement | Position): o is IMovement {
return (o as IMovement).start !== undefined && (o as IMovement).stop !== undefined;
Expand Down Expand Up @@ -666,7 +667,7 @@ class MoveFindForward extends BaseMovement {
count: number
): Promise<Position | IMovement> {
count = count || 1;
const toFind = this.keysPressed[1];
const toFind = Notation.ToControlCharacter(this.keysPressed[1]);
let result = position.findForwards(toFind, count);

if (!result) {
Expand Down Expand Up @@ -699,7 +700,7 @@ class MoveFindBackward extends BaseMovement {
count: number
): Promise<Position | IMovement> {
count = count || 1;
const toFind = this.keysPressed[1];
const toFind = Notation.ToControlCharacter(this.keysPressed[1]);
let result = position.findBackwards(toFind, count);

if (!result) {
Expand Down Expand Up @@ -728,7 +729,7 @@ class MoveTilForward extends BaseMovement {
count: number
): Promise<Position | IMovement> {
count = count || 1;
const toFind = this.keysPressed[1];
const toFind = Notation.ToControlCharacter(this.keysPressed[1]);
let result = position.tilForwards(toFind, count);

// For t<character> vim executes ; as 2; and , as 2,
Expand Down Expand Up @@ -766,7 +767,7 @@ class MoveTilBackward extends BaseMovement {
count: number
): Promise<Position | IMovement> {
count = count || 1;
const toFind = this.keysPressed[1];
const toFind = Notation.ToControlCharacter(this.keysPressed[1]);
let result = position.tilBackwards(toFind, count);

// For T<character> vim executes ; as 2; and , as 2,
Expand Down
11 changes: 10 additions & 1 deletion src/configuration/notation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'lodash';

export class Notation {
// Mapping from the nomalized string to regex strings that could match it.
// Mapping from the normalized string to regex strings that could match it.
private static _notationMap: { [key: string]: string[] } = {
'C-': ['ctrl\\+', 'c\\-'],
'D-': ['cmd\\+', 'd\\-'],
Expand All @@ -15,6 +15,15 @@ export class Notation {
'\n': ['<cr>', '<enter>'],
};

// Converts keystroke like <tab> to a single control character like \t
public static ToControlCharacter(key: string) {
if (key === "<tab>") {
return '\t';
}

return key;
}

public static IsControlKey(key: string): boolean {
key = key.toLocaleUpperCase();
return (
Expand Down
7 changes: 7 additions & 0 deletions test/mode/normalModeTests/motions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ suite('Motions in Normal Mode', () => {
end: ['text |text'],
});

newTest({
title: "Can handle 'f' with <tab>",
start: ['|text\tttext'],
keysPressed: 'f<tab>',
end: ['text|\tttext'],
});

newTest({
title: "Can handle 'F'",
start: ['text tex|t'],
Expand Down

0 comments on commit cb3a9fc

Please sign in to comment.