From b1d186b66216106329f1301e29892c1cac0fd9d2 Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Wed, 15 Nov 2017 22:42:09 +0900 Subject: [PATCH 1/5] Add c-n, c-p, c-m to console Add `c-n`, `c-j` for select next item. Add `c-p`, `c-k` for select previous item. Add `c-m` for select item. Above console keybinds are same as Vim(Vimperator)'s completion selector. --- src/console/components/console.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/console/components/console.js b/src/console/components/console.js index 7bc3364..cabd229 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -48,6 +48,34 @@ export default class ConsoleComponent { e.stopPropagation(); e.preventDefault(); break; + case KeyboardEvent.DOM_VK_OPEN_BRACKET: + if (e.ctrlKey) { + return this.hideCommand(); + } + break; + case KeyboardEvent.DOM_VK_M: + if (e.ctrlKey) { + e.stopPropagation(); + e.preventDefault(); + return this.onEntered(e.target.value); + } + break; + case KeyboardEvent.DOM_VK_N: + case KeyboardEvent.DOM_VK_J: + if (e.ctrlKey) { + this.store.dispatch(consoleActions.completionNext()); + e.stopPropagation(); + e.preventDefault(); + } + break; + case KeyboardEvent.DOM_VK_P: + case KeyboardEvent.DOM_VK_K: + if (e.ctrlKey) { + this.store.dispatch(consoleActions.completionPrev()); + e.stopPropagation(); + e.preventDefault(); + } + break; } } From f32dce829c90f67776c6827a8f7e493615a88aaf Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Thu, 16 Nov 2017 21:50:44 +0900 Subject: [PATCH 2/5] Add allow up and down to move cursor Also refactor methods. --- src/console/components/console.js | 40 +++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/console/components/console.js b/src/console/components/console.js index cabd229..7c1976e 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -31,14 +31,30 @@ export default class ConsoleComponent { } } + doEnter(e) { + e.stopPropagation(); + e.preventDefault(); + return this.onEntered(e.target.value); + } + + selectNext(e) { + this.store.dispatch(consoleActions.completionNext()); + e.stopPropagation(); + e.preventDefault(); + } + + selectPrev(e) { + this.store.dispatch(consoleActions.completionPrev()); + e.stopPropagation(); + e.preventDefault(); + } + onKeyDown(e) { switch (e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: return this.hideCommand(); case KeyboardEvent.DOM_VK_RETURN: - e.stopPropagation(); - e.preventDefault(); - return this.onEntered(e.target.value); + return this.doEnter(e); case KeyboardEvent.DOM_VK_TAB: if (e.shiftKey) { this.store.dispatch(consoleActions.completionPrev()); @@ -55,25 +71,25 @@ export default class ConsoleComponent { break; case KeyboardEvent.DOM_VK_M: if (e.ctrlKey) { - e.stopPropagation(); - e.preventDefault(); - return this.onEntered(e.target.value); + this.doEnter(e); } break; + case KeyboardEvent.DOM_VK_DOWN: + this.selectNext(e); + break; case KeyboardEvent.DOM_VK_N: case KeyboardEvent.DOM_VK_J: if (e.ctrlKey) { - this.store.dispatch(consoleActions.completionNext()); - e.stopPropagation(); - e.preventDefault(); + this.selectNext(e); } break; + case KeyboardEvent.DOM_VK_UP: + this.selectPrev(e); + break; case KeyboardEvent.DOM_VK_P: case KeyboardEvent.DOM_VK_K: if (e.ctrlKey) { - this.store.dispatch(consoleActions.completionPrev()); - e.stopPropagation(); - e.preventDefault(); + this.selectPrev(e); } break; } From 9ce54583314444a7f6c41db731be5d58f669702a Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Thu, 16 Nov 2017 23:22:56 +0900 Subject: [PATCH 3/5] Fix add return statement --- src/console/components/console.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console/components/console.js b/src/console/components/console.js index 7c1976e..682d5dc 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -71,7 +71,7 @@ export default class ConsoleComponent { break; case KeyboardEvent.DOM_VK_M: if (e.ctrlKey) { - this.doEnter(e); + return this.doEnter(e); } break; case KeyboardEvent.DOM_VK_DOWN: From b70a671d7e7c8b801f8a05210c71f7c9a8e48828 Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Sat, 18 Nov 2017 13:22:43 +0900 Subject: [PATCH 4/5] Fix drop , from cursor selector Because these are not Vim's default behavior. --- src/console/components/console.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/console/components/console.js b/src/console/components/console.js index 682d5dc..21439ef 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -78,7 +78,6 @@ export default class ConsoleComponent { this.selectNext(e); break; case KeyboardEvent.DOM_VK_N: - case KeyboardEvent.DOM_VK_J: if (e.ctrlKey) { this.selectNext(e); } @@ -87,7 +86,6 @@ export default class ConsoleComponent { this.selectPrev(e); break; case KeyboardEvent.DOM_VK_P: - case KeyboardEvent.DOM_VK_K: if (e.ctrlKey) { this.selectPrev(e); } From 5d0554c7e8be7d2e96a76927b46a37c82e0eb011 Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Sat, 18 Nov 2017 13:53:33 +0900 Subject: [PATCH 5/5] Fix drop arrow keys from console --- src/console/components/console.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/console/components/console.js b/src/console/components/console.js index 21439ef..7c23dab 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -74,17 +74,11 @@ export default class ConsoleComponent { return this.doEnter(e); } break; - case KeyboardEvent.DOM_VK_DOWN: - this.selectNext(e); - break; case KeyboardEvent.DOM_VK_N: if (e.ctrlKey) { this.selectNext(e); } break; - case KeyboardEvent.DOM_VK_UP: - this.selectPrev(e); - break; case KeyboardEvent.DOM_VK_P: if (e.ctrlKey) { this.selectPrev(e);