From 750b7571f58dd3d7f65d966132996210b5887694 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 14 Aug 2020 18:35:46 +0300 Subject: [PATCH] feature(key) vim: add ability to navigate using to first and last file using ^ and $ --- HELP.md | 4 +-- client/key/vim/index.spec.js | 47 ++++++++++++++++++++++++++++++++++-- client/key/vim/vim.js | 4 +-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/HELP.md b/HELP.md index bf9de6e2..cf92c031 100644 --- a/HELP.md +++ b/HELP.md @@ -216,8 +216,8 @@ When the `--vim` option is provided, or the configuration parameter `vim` is set | `j` | navigate to next file | `k` | navigate to previous file | `dd` | remove current file -| `G` | navigate to bottom file -| `gg` | navigate to top file +| `G` or `$` | navigate to bottom file +| `gg` or `^` | navigate to top file | `v` | visual mode | `y` | copy (selected in visual mode files) | `p` | paste files diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index e7048ca2..93a35816 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -270,7 +270,7 @@ test('cloudcmd: client: key: selectFile', (t) => { t.end(); }); -test('cloudcmd: client: key: set last file current', (t) => { +test('cloudcmd: client: key: set last file current: shift + g', (t) => { const last = 'last'; const nextSibling = { nextSibling: last, @@ -291,7 +291,28 @@ test('cloudcmd: client: key: set last file current', (t) => { t.end(); }); -test('cloudcmd: client: key: set first file current', (t) => { +test('cloudcmd: client: key: set last file current: $', (t) => { + const last = 'last'; + const nextSibling = { + nextSibling: last, + }; + const element = { + nextSibling, + }; + + const setCurrentFile = stub(); + + global.DOM.CurrentInfo.element = element; + global.DOM.setCurrentFile = setCurrentFile; + + vim('$', {}); + + t.ok(setCurrentFile.calledWith(last), 'should set last file'); + + t.end(); +}); + +test('cloudcmd: client: key: set first file current: gg', (t) => { const first = 'first'; const previousSibling = { previousSibling: first, @@ -314,6 +335,28 @@ test('cloudcmd: client: key: set first file current', (t) => { t.end(); }); +test('cloudcmd: client: key: set first file current: ^', (t) => { + const first = 'first'; + const previousSibling = { + previousSibling: first, + }; + + const element = { + previousSibling, + }; + + const setCurrentFile = stub(); + + global.DOM.CurrentInfo.element = element; + global.DOM.setCurrentFile = setCurrentFile; + + vim('^', {}); + + t.ok(setCurrentFile.calledWith(first), 'should set first file'); + + t.end(); +}); + test('cloudcmd: client: key: visual', (t) => { const element = { }; diff --git a/client/key/vim/vim.js b/client/key/vim/vim.js index cee0293a..e108c493 100644 --- a/client/key/vim/vim.js +++ b/client/key/vim/vim.js @@ -79,7 +79,7 @@ module.exports = (key, operations) => { return end(); } - if (/^gg$/.test(value)) { + if (value === 'gg' || key === '^') { const { isDelete, isVisual, @@ -100,7 +100,7 @@ module.exports = (key, operations) => { return end(); } - if (key === 'G') { + if (key === 'G' || key === '$') { moveNext({ count: Infinity, isVisual,