From 291dc39c25ec20b844ea918d093471ac3c0147fd Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 14 Aug 2020 19:04:49 +0300 Subject: [PATCH] feature(key) vim: add ability to navigate to next and previous using w and b --- client/key/vim/vim.js | 4 +-- client/key/vim/vim.spec.js | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/client/key/vim/vim.js b/client/key/vim/vim.js index e108c493..7a3d4017 100644 --- a/client/key/vim/vim.js +++ b/client/key/vim/vim.js @@ -47,7 +47,7 @@ module.exports = (key, operations) => { return end(); } - if (key === 'j') { + if (key === 'j' || key === 'w') { const { count, isDelete, @@ -63,7 +63,7 @@ module.exports = (key, operations) => { return end(); } - if (key === 'k') { + if (key === 'k' || key === 'b') { const { count, isDelete, diff --git a/client/key/vim/vim.spec.js b/client/key/vim/vim.spec.js index 5355807d..ecafb8a3 100644 --- a/client/key/vim/vim.spec.js +++ b/client/key/vim/vim.spec.js @@ -1,6 +1,8 @@ 'use strict'; const test = require('supertape'); +const stub = require('@cloudcmd/stub'); + const vim = require('./vim'); test('vim: no operations', (t) => { @@ -10,3 +12,54 @@ test('vim: no operations', (t) => { t.end(); }); +test('vim: ^', (t) => { + const movePrevious = stub(); + + vim('^', { + movePrevious, + }); + + const expected = { + count: Infinity, + isVisual: false, + isDelete: false, + }; + + t.ok(movePrevious.calledWith(expected), 'should call movePrevious'); + t.end(); +}); + +test('vim: w', (t) => { + const moveNext = stub(); + + vim('w', { + moveNext, + }); + + const expected = { + count: 1, + isVisual: false, + isDelete: false, + }; + + t.ok(moveNext.calledWith(expected), 'should call moveNext'); + t.end(); +}); + +test('vim: b', (t) => { + const movePrevious = stub(); + + vim('b', { + movePrevious, + }); + + const expected = { + count: 1, + isVisual: false, + isDelete: false, + }; + + t.ok(movePrevious.calledWith(expected), 'should call movePrevious'); + t.end(); +}); +