Skip to content

Commit

Permalink
Merge pull request VSCodeVim#3081 from shawnaxsom/feature/fix-black-h…
Browse files Browse the repository at this point in the history
…ole-operator-mappings

Feature/fix black hole operator mappings
  • Loading branch information
jpoon authored Oct 2, 2018
2 parents cbb0e12 + 0ff591f commit bd153ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class ModeHandler implements vscode.Disposable {
*/
if (
!this.vimState.isCurrentlyPerformingRemapping &&
!this.vimState.recordedState.operator &&
(withinTimeout || this.vimState.recordedState.commandList.length === 1)
) {
handled = await this._remappers.sendKey(
Expand Down
52 changes: 52 additions & 0 deletions test/configuration/remapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import { ModeHandler } from '../../src/mode/modeHandler';
import { Configuration } from '../testConfiguration';
import { assertEqual, setupWorkspace, cleanUpWorkspace } from '../testUtils';
import { IKeyRemapping } from '../../src/configuration/iconfiguration';
import { IRegisterContent, Register } from '../../src/register/register';
import { getAndUpdateModeHandler } from '../../extension';
import { VimState } from '../../src/state/vimState';

/* tslint:disable:no-string-literal */

suite('Remapper', () => {
let modeHandler: ModeHandler;
let vimState: VimState;
const leaderKey = '\\';
const insertModeKeyBindings: IKeyRemapping[] = [
{
Expand All @@ -39,6 +42,18 @@ suite('Remapper', () => {
},
],
},
{
before: ['d'],
after: ['"', '_', 'd'],
},
{
before: ['y', 'y'],
after: ['y', 'l'],
},
{
before: ['e'],
after: ['$'],
},
];
const visualModeKeyBindings: IKeyRemapping[] = [
{
Expand Down Expand Up @@ -81,6 +96,7 @@ suite('Remapper', () => {

await setupWorkspace(configuration);
modeHandler = await getAndUpdateModeHandler();
vimState = modeHandler.vimState;
});

teardown(cleanUpWorkspace);
Expand Down Expand Up @@ -271,6 +287,42 @@ suite('Remapper', () => {
assert.equal(actual, true);
assert.equal(vscode.window.visibleTextEditors.length, 0);
});

test('d -> black hole register delete in normal mode through modehandler', async () => {
assert.equal(modeHandler.currentMode.name, ModeName.Normal);

await modeHandler.handleMultipleKeyEvents(['<Esc>', 'g', 'g']);
await modeHandler.handleMultipleKeyEvents(['i', 'line1', '<Esc>', '0']);

const expected = 'text-to-put-on-register';
let actual: IRegisterContent;
Register.put(expected, modeHandler.vimState);
actual = await Register.get(vimState);
assert.equal(actual.text, expected);

await modeHandler.handleMultipleKeyEvents(['d', 'd']);

actual = await Register.get(vimState);
assert.equal(actual.text, expected);
});

test('d -> black hole register delete in normal mode through modehandler', async () => {
assert.equal(modeHandler.currentMode.name, ModeName.Normal);

await modeHandler.handleMultipleKeyEvents(['<Esc>', 'g', 'g']);
await modeHandler.handleMultipleKeyEvents(['i', 'word1 word2', '<Esc>', '0']);

const expected = 'text-to-put-on-register';
let actual: IRegisterContent;
Register.put(expected, modeHandler.vimState);
actual = await Register.get(vimState);
assert.equal(actual.text, expected);

await modeHandler.handleMultipleKeyEvents(['d', 'w']);

actual = await Register.get(vimState);
assert.equal(actual.text, expected);
});
});

/* tslint:enable:no-string-literal */

0 comments on commit bd153ad

Please sign in to comment.