aboutsummaryrefslogtreecommitdiff
path: root/src/console/reducers
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-11 11:18:01 +0000
committerGitHub <noreply@github.com>2017-11-11 11:18:01 +0000
commit0630c8f56664ac48f4cf8799dc1d88a6388957a6 (patch)
treed9160c76f4c3435b0859669f1254b12eb92d183f /src/console/reducers
parent86b534b1e1de03d51efb9f28cd32296d037f07fc (diff)
parentfe8a9283172e43e29480c4293c34565859c04c32 (diff)
Merge pull request #142 from ueokande/find-mode
[WIP] Find 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: