diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-17 09:00:41 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-17 09:00:41 +0900 |
commit | cd4708898134f5966f87df4aeaa8ed8c60e7943f (patch) | |
tree | db082d9cb2ec426010556dbc24ab439c9757afbd /src/actions/command.js | |
parent | c5529958d53146c8c6826673abe6431a19f1924d (diff) | |
parent | 9ae814dfe45426f8df9b89b305392770344a7d50 (diff) |
Merge branch 'lint'
Diffstat (limited to 'src/actions/command.js')
-rw-r--r-- | src/actions/command.js | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/actions/command.js b/src/actions/command.js index 03f1e83..3e6eadb 100644 --- a/src/actions/command.js +++ b/src/actions/command.js @@ -3,36 +3,39 @@ import * as consoleActions from './console'; const normalizeUrl = (string) => { try { - return new URL(string).href + return new URL(string).href; } catch (e) { return 'http://' + string; } -} +}; const openCommand = (url) => { - return browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { - if (tabs.length > 0) { - return browser.tabs.update(tabs[0].id, { url: url }); + return browser.tabs.query({ + active: true, currentWindow: true + }).then((gotTabs) => { + if (gotTabs.length > 0) { + return browser.tabs.update(gotTabs[0].id, { url: url }); } }); -} +}; const tabopenCommand = (url) => { return browser.tabs.create({ url: url }); -} +}; const bufferCommand = (keywords) => { - return browser.tabs.query({ active: true, currentWindow: true }).then((tabss) => { - if (tabss.length > 0) { + return browser.tabs.query({ + active: true, currentWindow: true + }).then((gotTabs) => { + if (gotTabs.length > 0) { if (isNaN(keywords)) { - return tabs.selectByKeyword(tabss[0], keywords); - } else { - let index = parseInt(keywords, 10) - 1; - return tabs.selectAt(index); + return tabs.selectByKeyword(gotTabs[0], keywords); } + let index = parseInt(keywords, 10) - 1; + return tabs.selectAt(index); } }); -} +}; const doCommand = (name, remaining) => { switch (name) { @@ -46,39 +49,43 @@ const doCommand = (name, remaining) => { return bufferCommand(remaining); } throw new Error(name + ' command is not defined'); -} +}; const getCompletions = (command, keywords) => { switch (command) { case 'buffer': - return tabs.getCompletions(keywords).then((tabs) => { - let items = tabs.map((tab) => { + return tabs.getCompletions(keywords).then((gotTabs) => { + let items = gotTabs.map((tab) => { return { caption: tab.title, content: tab.title, url: tab.url, icon: tab.favIconUrl - } + }; }); - return [{ - name: "Buffers", - items: items - }]; + return [ + { + name: 'Buffers', + items: items + } + ]; }); } return Promise.resolve([]); }; -export function exec(line) { +const exec = (line) => { let name = line.split(' ')[0]; let remaining = line.replace(name + ' ', ''); return doCommand(name, remaining).then(() => { return consoleActions.hide(); }); -} +}; -export function complete(line) { +const complete = (line) => { let command = line.split(' ', 1)[0]; let keywords = line.replace(command + ' ', ''); return getCompletions(command, keywords).then(consoleActions.setCompletions); -} +}; + +export { exec, complete }; |