Skip to content
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

Feature/fix black hole operator mappings #3081

Merged
Merged
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
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 */