aboutsummaryrefslogtreecommitdiff
path: root/src/components/console.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/console.js')
-rw-r--r--src/components/console.js30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/components/console.js b/src/components/console.js
index 9580dcf..12341c1 100644
--- a/src/components/console.js
+++ b/src/components/console.js
@@ -1,5 +1,5 @@
-import messages from '../content/messages';
-import * as completionActions from '../actions/completion';
+import messages from 'content/messages';
+import * as consoleActions from 'actions/console';
export default class ConsoleComponent {
constructor(wrapper, store) {
@@ -36,12 +36,12 @@ export default class ConsoleComponent {
return browser.runtime.sendMessage({
type: messages.CONSOLE_ENTERED,
text: e.target.value
- });
+ }).then(this.onBlur);
case KeyboardEvent.DOM_VK_TAB:
if (e.shiftKey) {
- this.store.dispatch(completionActions.selectPrev());
+ this.store.dispatch(consoleActions.completionPrev());
} else {
- this.store.dispatch(completionActions.selectNext());
+ this.store.dispatch(consoleActions.completionNext());
}
e.stopPropagation();
e.preventDefault();
@@ -63,13 +63,15 @@ export default class ConsoleComponent {
this.prevValue = e.target.value;
return browser.runtime.sendMessage({
- type: messages.CONSOLE_CHANGEED,
+ type: messages.CONSOLE_QUERY_COMPLETIONS,
text: e.target.value
+ }).then((completions) => {
+ this.store.dispatch(consoleActions.setCompletions(completions));
});
}
- // TODO use store/reducer to update state.
- update(state) {
+ update() {
+ let state = this.store.getState().console;
if (!this.prevState.commandShown && state.commandShown) {
this.showCommand(state.commandText);
} else if (!state.commandShown) {
@@ -83,6 +85,18 @@ export default class ConsoleComponent {
this.hideError();
}
+ if (state.groupSelection >= 0 && state.itemSelection >= 0) {
+ let group = state.completions[state.groupSelection];
+ let item = group.items[state.itemSelection];
+ this.setCommandValue(item.content);
+ } else if (state.completions.length > 0 &&
+ JSON.stringify(this.prevState.completions) ===
+ JSON.stringify(state.completions)) {
+ // Reset input only completion groups not changed (unselected an item in
+ // completion) in order to avoid to override previous input
+ this.setCommandCompletionOrigin();
+ }
+
this.prevState = state;
}