aboutsummaryrefslogtreecommitdiff
path: root/src/console/reducers
diff options
context:
space:
mode:
Diffstat (limited to 'src/console/reducers')
-rw-r--r--src/console/reducers/index.js32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js
index d4affa7..60c0007 100644
--- a/src/console/reducers/index.js
+++ b/src/console/reducers/index.js
@@ -3,7 +3,8 @@ import actions from 'console/actions';
const defaultState = {
mode: '',
messageText: '',
- commandText: '',
+ consoleText: '',
+ completionSource: '',
completions: [],
groupSelection: -1,
itemSelection: -1,
@@ -43,13 +44,25 @@ const prevSelection = (state) => {
return [state.groupSelection, state.itemSelection - 1];
};
+const nextConsoleText = (completions, group, item, defaults) => {
+ if (group < 0 || item < 0) {
+ return defaults;
+ }
+ return completions[group].items[item].content;
+};
+
export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.CONSOLE_SHOW_COMMAND:
return Object.assign({}, state, {
mode: 'command',
- commandText: action.text,
- errorShown: false,
+ consoleText: action.text,
+ completions: []
+ });
+ case actions.CONSOLE_SHOW_FIND:
+ return Object.assign({}, state, {
+ mode: 'find',
+ consoleText: '',
completions: []
});
case actions.CONSOLE_SHOW_ERROR:
@@ -64,11 +77,16 @@ export default function reducer(state = defaultState, action = {}) {
});
case actions.CONSOLE_HIDE_COMMAND:
return Object.assign({}, state, {
- mode: state.mode === 'command' ? '' : state.mode,
+ mode: state.mode === 'command' || state.mode === 'find' ? '' : state.mode,
+ });
+ case actions.CONSOLE_SET_CONSOLE_TEXT:
+ return Object.assign({}, state, {
+ consoleText: action.consoleText,
});
case actions.CONSOLE_SET_COMPLETIONS:
return Object.assign({}, state, {
completions: action.completions,
+ completionSource: action.completionSource,
groupSelection: -1,
itemSelection: -1,
});
@@ -77,6 +95,9 @@ export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
groupSelection: next[0],
itemSelection: next[1],
+ consoleText: nextConsoleText(
+ state.completions, next[0], next[1],
+ state.completionSource),
});
}
case actions.CONSOLE_COMPLETION_PREV: {
@@ -84,6 +105,9 @@ export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
groupSelection: next[0],
itemSelection: next[1],
+ consoleText: nextConsoleText(
+ state.completions, next[0], next[1],
+ state.completionSource),
});
}
default: