aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Ohyanagi <heavenshell.jp@gmail.com>2017-11-16 21:50:44 +0900
committerShinya Ohyanagi <heavenshell.jp@gmail.com>2017-11-16 21:50:44 +0900
commitf32dce829c90f67776c6827a8f7e493615a88aaf (patch)
tree40545f3a7dd5cc4e1a131ed4db247c4dc7956106
parentb1d186b66216106329f1301e29892c1cac0fd9d2 (diff)
Add allow up and down to move cursor
Also refactor methods.
-rw-r--r--src/console/components/console.js40
1 files 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;
}