aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions/completion.js22
-rw-r--r--src/actions/console.js26
-rw-r--r--src/actions/index.js10
-rw-r--r--src/components/completion.js6
-rw-r--r--src/components/console.js20
-rw-r--r--src/pages/console.js14
-rw-r--r--src/reducers/completion.js68
-rw-r--r--src/reducers/console.js60
-rw-r--r--src/reducers/index.js3
9 files changed, 101 insertions, 128 deletions
diff --git a/src/actions/completion.js b/src/actions/completion.js
deleted file mode 100644
index 733f516..0000000
--- a/src/actions/completion.js
+++ /dev/null
@@ -1,22 +0,0 @@
-import actions from 'actions';
-
-const setItems = (groups) => {
- return {
- type: actions.COMPLETION_SET_ITEMS,
- groups,
- };
-};
-
-const selectNext = () => {
- return {
- type: actions.COMPLETION_SELECT_NEXT
- };
-};
-
-const selectPrev = () => {
- return {
- type: actions.COMPLETION_SELECT_PREV
- };
-};
-
-export { setItems, selectNext, selectPrev };
diff --git a/src/actions/console.js b/src/actions/console.js
index ba1fbeb..4183489 100644
--- a/src/actions/console.js
+++ b/src/actions/console.js
@@ -7,6 +7,19 @@ const showCommand = (text) => {
};
};
+const showError = (text) => {
+ return {
+ type: actions.CONSOLE_SHOW_ERROR,
+ text: text
+ };
+};
+
+const hide = () => {
+ return {
+ type: actions.CONSOLE_HIDE
+ };
+};
+
const setCompletions = (completions) => {
return {
type: actions.CONSOLE_SET_COMPLETIONS,
@@ -14,17 +27,18 @@ const setCompletions = (completions) => {
};
};
-const showError = (text) => {
+const completionNext = () => {
return {
- type: actions.CONSOLE_SHOW_ERROR,
- text: text
+ type: actions.CONSOLE_COMPLETION_NEXT,
};
};
-const hide = () => {
+const completionPrev = () => {
return {
- type: actions.CONSOLE_HIDE
+ type: actions.CONSOLE_COMPLETION_PREV,
};
};
-export { showCommand, setCompletions, showError, hide };
+export {
+ showCommand, showError, hide, setCompletions, completionNext, completionPrev
+};
diff --git a/src/actions/index.js b/src/actions/index.js
index 4e8d4a7..6a64795 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -1,9 +1,11 @@
export default {
// console commands
- CONSOLE_SHOW_COMMAND: 'vimvixen.console.show.command',
- CONSOLE_SET_COMPLETIONS: 'vimvixen.console.set.completions',
- CONSOLE_SHOW_ERROR: 'vimvixen.console.show.error',
- CONSOLE_HIDE: 'vimvixen.console.hide',
+ CONSOLE_SHOW_COMMAND: 'console.show.command',
+ CONSOLE_SET_COMPLETIONS: 'console.set.completions',
+ CONSOLE_SHOW_ERROR: 'console.show.error',
+ CONSOLE_HIDE: 'console.hide',
+ CONSOLE_COMPLETION_NEXT: 'console.completion.next',
+ CONSOLE_COMPLETION_PREV: 'console.completion.prev',
// User input
INPUT_KEY_PRESS: 'input.key,press',
diff --git a/src/components/completion.js b/src/components/completion.js
index d1fdd06..f527a84 100644
--- a/src/components/completion.js
+++ b/src/components/completion.js
@@ -6,15 +6,15 @@ export default class Completion {
}
update() {
- let state = this.store.getState().completion;
+ let state = this.store.getState().console;
if (JSON.stringify(this.prevState) === JSON.stringify(state)) {
return;
}
this.wrapper.innerHTML = '';
- for (let i = 0; i < state.groups.length; ++i) {
- let group = state.groups[i];
+ for (let i = 0; i < state.completions.length; ++i) {
+ let group = state.completions[i];
let title = this.createCompletionTitle(group.name);
this.wrapper.append(title);
diff --git a/src/components/console.js b/src/components/console.js
index 3a7f88b..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 * as consoleActions from 'actions/console';
export default class ConsoleComponent {
constructor(wrapper, store) {
@@ -39,9 +39,9 @@ export default class ConsoleComponent {
}).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();
@@ -66,7 +66,7 @@ export default class ConsoleComponent {
type: messages.CONSOLE_QUERY_COMPLETIONS,
text: e.target.value
}).then((completions) => {
- this.store.dispatch(completionActions.setItems(completions));
+ this.store.dispatch(consoleActions.setCompletions(completions));
});
}
@@ -85,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;
}
diff --git a/src/pages/console.js b/src/pages/console.js
index 4d3dd3f..20a60f6 100644
--- a/src/pages/console.js
+++ b/src/pages/console.js
@@ -9,7 +9,6 @@ import * as consoleActions from 'actions/console';
const store = createStore(reducers);
let completionComponent = null;
let consoleComponent = null;
-let prevState = {};
window.addEventListener('load', () => {
let wrapper = document.querySelector('#vimvixen-console-completion');
@@ -21,19 +20,6 @@ window.addEventListener('load', () => {
store.subscribe(() => {
completionComponent.update();
consoleComponent.update();
-
- let state = store.getState().completion;
-
- if (state.groupSelection >= 0) {
- let item = state.groups[state.groupSelection].items[state.itemSelection];
- consoleComponent.setCommandValue(item.content);
- } else if (state.groups.length > 0 &&
- JSON.stringify(prevState.groups) === JSON.stringify(state.groups)) {
- // Reset input only completion groups not changed (unselected an item in
- // completion) in order to avoid to override previous input
- consoleComponent.setCommandCompletionOrigin();
- }
- prevState = state;
});
browser.runtime.onMessage.addListener((action) => {
diff --git a/src/reducers/completion.js b/src/reducers/completion.js
deleted file mode 100644
index f85a500..0000000
--- a/src/reducers/completion.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import actions from 'actions';
-
-const defaultState = {
- groupSelection: -1,
- itemSelection: -1,
- groups: [],
-};
-
-const nextSelection = (state) => {
- if (state.groupSelection < 0) {
- return [0, 0];
- }
-
- let group = state.groups[state.groupSelection];
- if (state.groupSelection + 1 >= state.groups.length &&
- state.itemSelection + 1 >= group.items.length) {
- return [-1, -1];
- }
- if (state.itemSelection + 1 >= group.items.length) {
- return [state.groupSelection + 1, 0];
- }
- return [state.groupSelection, state.itemSelection + 1];
-};
-
-const prevSelection = (state) => {
- if (state.groupSelection < 0) {
- return [
- state.groups.length - 1,
- state.groups[state.groups.length - 1].items.length - 1
- ];
- }
- if (state.groupSelection === 0 && state.itemSelection === 0) {
- return [-1, -1];
- } else if (state.itemSelection === 0) {
- return [
- state.groupSelection - 1,
- state.groups[state.groupSelection - 1].items.length - 1
- ];
- }
- return [state.groupSelection, state.itemSelection - 1];
-};
-
-export default function reducer(state = defaultState, action = {}) {
- switch (action.type) {
- case actions.COMPLETION_SET_ITEMS:
- return Object.assign({}, state, {
- groups: action.groups,
- groupSelection: -1,
- itemSelection: -1,
- });
- case actions.COMPLETION_SELECT_NEXT: {
- let next = nextSelection(state);
- return Object.assign({}, state, {
- groupSelection: next[0],
- itemSelection: next[1],
- });
- }
- case actions.COMPLETION_SELECT_PREV: {
- let next = prevSelection(state);
- return Object.assign({}, state, {
- groupSelection: next[0],
- itemSelection: next[1],
- });
- }
- default:
- return state;
- }
-}
diff --git a/src/reducers/console.js b/src/reducers/console.js
index 3e63672..b9ed5b8 100644
--- a/src/reducers/console.js
+++ b/src/reducers/console.js
@@ -6,6 +6,42 @@ const defaultState = {
commandShown: false,
commandText: '',
completions: [],
+ groupSelection: -1,
+ itemSelection: -1,
+};
+
+const nextSelection = (state) => {
+ if (state.groupSelection < 0) {
+ return [0, 0];
+ }
+
+ let group = state.completions[state.groupSelection];
+ if (state.groupSelection + 1 >= state.completions.length &&
+ state.itemSelection + 1 >= group.items.length) {
+ return [-1, -1];
+ }
+ if (state.itemSelection + 1 >= group.items.length) {
+ return [state.groupSelection + 1, 0];
+ }
+ return [state.groupSelection, state.itemSelection + 1];
+};
+
+const prevSelection = (state) => {
+ if (state.groupSelection < 0) {
+ return [
+ state.completions.length - 1,
+ state.completions[state.completions.length - 1].items.length - 1
+ ];
+ }
+ if (state.groupSelection === 0 && state.itemSelection === 0) {
+ return [-1, -1];
+ } else if (state.itemSelection === 0) {
+ return [
+ state.groupSelection - 1,
+ state.completions[state.groupSelection - 1].items.length - 1
+ ];
+ }
+ return [state.groupSelection, state.itemSelection - 1];
};
export default function reducer(state = defaultState, action = {}) {
@@ -17,10 +53,6 @@ export default function reducer(state = defaultState, action = {}) {
errorShown: false,
completions: []
});
- case actions.CONSOLE_SET_COMPLETIONS:
- return Object.assign({}, state, {
- completions: action.completions
- });
case actions.CONSOLE_SHOW_ERROR:
return Object.assign({}, state, {
errorText: action.text,
@@ -36,6 +68,26 @@ export default function reducer(state = defaultState, action = {}) {
errorShown: false,
commandShown: false
});
+ case actions.CONSOLE_SET_COMPLETIONS:
+ return Object.assign({}, state, {
+ completions: action.completions,
+ groupSelection: -1,
+ itemSelection: -1,
+ });
+ case actions.CONSOLE_COMPLETION_NEXT: {
+ let next = nextSelection(state);
+ return Object.assign({}, state, {
+ groupSelection: next[0],
+ itemSelection: next[1],
+ });
+ }
+ case actions.CONSOLE_COMPLETION_PREV: {
+ let next = prevSelection(state);
+ return Object.assign({}, state, {
+ groupSelection: next[0],
+ itemSelection: next[1],
+ });
+ }
default:
return state;
}
diff --git a/src/reducers/index.js b/src/reducers/index.js
index 5a4f14b..8ed6452 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -2,14 +2,12 @@ import inputReducer from 'reducers/input';
import consoleReducer from 'reducers/console';
import settingReducer from 'reducers/setting';
import followReducer from 'reducers/follow';
-import completionReducer from 'reducers/completion';
const defaultState = {
input: inputReducer(undefined, {}),
console: consoleReducer(undefined, {}),
setting: settingReducer(undefined, {}),
follow: followReducer(undefined, {}),
- completion: completionReducer(undefined, {}),
};
export default function reducer(state = defaultState, action = {}) {
@@ -18,6 +16,5 @@ export default function reducer(state = defaultState, action = {}) {
console: consoleReducer(state.console, action),
setting: settingReducer(state.setting, action),
follow: followReducer(state.follow, action),
- completion: completionReducer(state.completion, action),
});
}