diff options
-rw-r--r-- | src/background/index.js | 2 | ||||
-rw-r--r-- | src/background/reducers/index.js | 23 | ||||
-rw-r--r-- | src/background/shared/completions/index.js | 82 | ||||
-rw-r--r-- | src/background/shared/versions/index.js (renamed from src/shared/versions/index.js) | 2 | ||||
-rw-r--r-- | src/background/shared/versions/release-notes.js (renamed from src/shared/versions/release-notes.js) | 0 | ||||
-rw-r--r-- | src/background/shared/versions/storage.js (renamed from src/shared/versions/storage.js) | 0 | ||||
-rw-r--r-- | src/console/reducers/index.js | 3 | ||||
-rw-r--r-- | src/content/reducers/index.js | 33 | ||||
-rw-r--r-- | src/shared/commands/docs.js | 11 | ||||
-rw-r--r-- | src/shared/settings/properties.js | 8 | ||||
-rw-r--r-- | test/background/shared/versions/index.test.js (renamed from test/shared/versions/index.test.js) | 4 | ||||
-rw-r--r-- | test/background/shared/versions/storage.test.js (renamed from test/shared/versions/storage.test.js) | 2 |
12 files changed, 110 insertions, 60 deletions
diff --git a/src/background/index.js b/src/background/index.js index 8c4eafc..1e4c078 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -6,7 +6,7 @@ import IndicatorComponent from 'background/components/indicator'; import reducers from 'background/reducers'; import { createStore, applyMiddleware } from 'redux'; import promise from 'redux-promise'; -import * as versions from 'shared/versions'; +import * as versions from './shared/versions'; const store = createStore( reducers, diff --git a/src/background/reducers/index.js b/src/background/reducers/index.js index 78f855c..465f927 100644 --- a/src/background/reducers/index.js +++ b/src/background/reducers/index.js @@ -1,17 +1,8 @@ -import settingReducer from './setting'; -import findReducer from './find'; -import tabReducer from './tab'; +import { combineReducers } from 'redux'; +import setting from './setting'; +import find from './find'; +import tab from './tab'; -// Make setting reducer instead of re-use -const defaultState = { - setting: settingReducer(undefined, {}), - find: findReducer(undefined, {}), - tab: tabReducer(undefined, {}), -}; - -export default function reducer(state = defaultState, action = {}) { - return { ...state, - setting: settingReducer(state.setting, action), - find: findReducer(state.find, action), - tab: tabReducer(state.tab, action), }; -} +export default combineReducers({ + setting, find, tab, +}); diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d5875fe..9ca13f7 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -1,6 +1,19 @@ +import commandDocs from 'shared/commands/docs'; import * as tabs from './tabs'; import * as histories from './histories'; import * as bookmarks from './bookmarks'; +import * as properties from 'shared/settings/properties'; + +const completeCommands = (typing) => { + let keys = Object.keys(commandDocs); + return keys + .filter(name => name.startsWith(typing)) + .map(name => ({ + caption: name, + content: name, + url: commandDocs[name], + })); +}; const getSearchCompletions = (command, keywords, searchConfig) => { let engineNames = Object.keys(searchConfig.engines); @@ -74,20 +87,63 @@ const getBufferCompletions = async(command, keywords, excludePinned) => { ]; }; -const getCompletions = (line, settings) => { - let typedWords = line.trim().split(/ +/); - let typing = ''; - if (!line.endsWith(' ')) { - typing = typedWords.pop(); +const getSetCompletions = (command, keywords) => { + let keys = Object.keys(properties.docs).filter( + name => name.startsWith(keywords) + ); + let items = keys.map((key) => { + if (properties.types[key] === 'boolean') { + return [ + { + caption: key, + content: command + ' ' + key, + url: 'Enable ' + properties.docs[key], + }, { + caption: 'no' + key, + content: command + ' no' + key, + url: 'Disable ' + properties.docs[key], + } + ]; + } + return [ + { + caption: key, + content: command + ' ' + key, + url: 'Set ' + properties.docs[key], + } + ]; + }); + items = items.reduce((acc, val) => acc.concat(val), []); + if (items.length === 0) { + return Promise.resolve([]); } + return Promise.resolve([ + { + name: 'Properties', + items, + } + ]); +}; - if (typedWords.length === 0) { - return Promise.resolve([]); +const complete = (line, settings) => { + let trimmed = line.trimStart(); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words.length === 1) { + let items = completeCommands(name); + if (items.length === 0) { + return Promise.resolve([]); + } + return Promise.resolve([ + { + name: 'Console Command', + items: completeCommands(name), + } + ]); } - let name = typedWords.shift(); - let keywords = typedWords.concat(typing).join(' '); + let keywords = trimmed.slice(name.length).trimStart(); - switch (name) { + switch (words[0]) { case 'o': case 'open': case 't': @@ -108,12 +164,10 @@ const getCompletions = (line, settings) => { case 'bdelete': case 'bdeletes': return getBufferCompletions(name, keywords, true); + case 'set': + return getSetCompletions(name, keywords); } return Promise.resolve([]); }; -const complete = (line, settings) => { - return getCompletions(line, settings); -}; - export { complete }; diff --git a/src/shared/versions/index.js b/src/background/shared/versions/index.js index ba3d183..aa09c92 100644 --- a/src/shared/versions/index.js +++ b/src/background/shared/versions/index.js @@ -1,6 +1,6 @@ import * as storage from './storage'; import * as releaseNotes from './release-notes'; -import manifest from '../../../manifest.json'; +import manifest from '../../../../manifest.json'; const NOTIFICATION_ID = 'vimvixen-update'; diff --git a/src/shared/versions/release-notes.js b/src/background/shared/versions/release-notes.js index 6ef2335..6ef2335 100644 --- a/src/shared/versions/release-notes.js +++ b/src/background/shared/versions/release-notes.js diff --git a/src/shared/versions/storage.js b/src/background/shared/versions/storage.js index 7883258..7883258 100644 --- a/src/shared/versions/storage.js +++ b/src/background/shared/versions/storage.js diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js index 71b0776..7dcad17 100644 --- a/src/console/reducers/index.js +++ b/src/console/reducers/index.js @@ -11,6 +11,9 @@ const defaultState = { }; const nextSelection = (state) => { + if (state.completions.length === 0) { + return [-1, -1]; + } if (state.groupSelection < 0) { return [0, 0]; } diff --git a/src/content/reducers/index.js b/src/content/reducers/index.js index c3a474e..6e6a147 100644 --- a/src/content/reducers/index.js +++ b/src/content/reducers/index.js @@ -1,25 +1,10 @@ -import addonReducer from './addon'; -import findReducer from './find'; -import settingReducer from './setting'; -import inputReducer from './input'; -import followControllerReducer from './follow-controller'; +import { combineReducers } from 'redux'; +import addon from './addon'; +import find from './find'; +import setting from './setting'; +import input from './input'; +import followController from './follow-controller'; -// Make setting reducer instead of re-use -const defaultState = { - addon: addonReducer(undefined, {}), - find: findReducer(undefined, {}), - setting: settingReducer(undefined, {}), - input: inputReducer(undefined, {}), - followController: followControllerReducer(undefined, {}), -}; - -export default function reducer(state = defaultState, action = {}) { - return { - ...state, - addon: addonReducer(state.addon, action), - find: findReducer(state.find, action), - setting: settingReducer(state.setting, action), - input: inputReducer(state.input, action), - followController: followControllerReducer(state.followController, action), - }; -} +export default combineReducers({ + addon, find, setting, input, followController, +}); diff --git a/src/shared/commands/docs.js b/src/shared/commands/docs.js new file mode 100644 index 0000000..c73eb71 --- /dev/null +++ b/src/shared/commands/docs.js @@ -0,0 +1,11 @@ +export default { + set: 'Set a value of the property', + open: 'Open a URL or search by keywords in current tab', + tabopen: 'Open a URL or search by keywords in new tab', + winopen: 'Open a URL or search by keywords in new window', + buffer: 'Sekect tabs by matched keywords', + bdelete: 'Close a certain tab matched by keywords', + bdeletes: 'Close all tabs matched by keywords', + quit: 'Close the current tab', + quitall: 'Close all tabs', +}; diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index 4bda8d6..b392cbb 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -15,4 +15,10 @@ const defaults = { adjacenttab: true, }; -export { types, defaults }; +const docs = { + hintchars: 'Hint characters on follow mode', + smoothscroll: 'smooth scroll', + adjacenttab: 'open adjacent tabs', +}; + +export { types, defaults, docs }; diff --git a/test/shared/versions/index.test.js b/test/background/shared/versions/index.test.js index d90f04c..d65dd9a 100644 --- a/test/shared/versions/index.test.js +++ b/test/background/shared/versions/index.test.js @@ -1,5 +1,5 @@ -import * as versions from 'shared/versions'; -import manifest from '../../../manifest.json'; +import * as versions from 'background/shared/versions'; +import manifest from '../../../../manifest.json'; describe("shared/versions/storage", () => { describe('#checkUpdated', () => { diff --git a/test/shared/versions/storage.test.js b/test/background/shared/versions/storage.test.js index f541abf..f452516 100644 --- a/test/shared/versions/storage.test.js +++ b/test/background/shared/versions/storage.test.js @@ -1,4 +1,4 @@ -import * as storage from 'shared/versions/storage'; +import * as storage from 'background/shared/versions/storage'; describe("shared/versions/storage", () => { describe('#load', () => { |