aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/actions/command.js2
-rw-r--r--src/background/components/background.js4
-rw-r--r--src/background/components/operation.js4
-rw-r--r--src/background/shared/completions/histories.js (renamed from src/background/histories.js)0
-rw-r--r--src/background/shared/completions/index.js84
-rw-r--r--src/background/shared/completions/tabs.js10
-rw-r--r--src/background/shared/tabs.js (renamed from src/background/tabs.js)11
-rw-r--r--src/background/shared/zooms.js (renamed from src/background/zooms.js)0
8 files changed, 100 insertions, 15 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js
index 4c52bca..2f7305a 100644
--- a/src/background/actions/command.js
+++ b/src/background/actions/command.js
@@ -1,5 +1,5 @@
import actions from '../actions';
-import * as tabs from 'background/tabs';
+import * as tabs from '../shared/tabs';
import * as parsers from 'shared/commands/parsers';
import * as properties from 'shared/settings/properties';
diff --git a/src/background/components/background.js b/src/background/components/background.js
index 81d815b..e13424b 100644
--- a/src/background/components/background.js
+++ b/src/background/components/background.js
@@ -3,7 +3,7 @@ import * as commandActions from 'background/actions/command';
import * as settingActions from 'background/actions/setting';
import * as findActions from 'background/actions/find';
import * as tabActions from 'background/actions/tab';
-import * as commands from 'shared/commands';
+import * as completions from '../shared/completions';
export default class BackgroundComponent {
constructor(store) {
@@ -44,7 +44,7 @@ export default class BackgroundComponent {
case messages.SETTINGS_QUERY:
return Promise.resolve(this.store.getState().setting.value);
case messages.CONSOLE_QUERY_COMPLETIONS:
- return commands.complete(message.text, settings.value);
+ return completions.complete(message.text, settings.value);
case messages.SETTINGS_RELOAD:
this.store.dispatch(settingActions.load());
return this.broadcastSettingsChanged();
diff --git a/src/background/components/operation.js b/src/background/components/operation.js
index e1094c5..b9581c9 100644
--- a/src/background/components/operation.js
+++ b/src/background/components/operation.js
@@ -1,7 +1,7 @@
import messages from 'shared/messages';
import operations from 'shared/operations';
-import * as tabs from 'background/tabs';
-import * as zooms from 'background/zooms';
+import * as tabs from '../shared//tabs';
+import * as zooms from '../shared/zooms';
export default class BackgroundComponent {
constructor(store) {
diff --git a/src/background/histories.js b/src/background/shared/completions/histories.js
index a7d3d47..a7d3d47 100644
--- a/src/background/histories.js
+++ b/src/background/shared/completions/histories.js
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
new file mode 100644
index 0000000..73b7b27
--- /dev/null
+++ b/src/background/shared/completions/index.js
@@ -0,0 +1,84 @@
+import * as tabs from './tabs';
+import * as histories from './histories';
+
+const getOpenCompletions = (command, keywords, searchConfig) => {
+ return histories.getCompletions(keywords).then((pages) => {
+ let historyItems = pages.map((page) => {
+ return {
+ caption: page.title,
+ content: command + ' ' + page.url,
+ url: page.url
+ };
+ });
+ let engineNames = Object.keys(searchConfig.engines);
+ let engineItems = engineNames.filter(name => name.startsWith(keywords))
+ .map(name => ({
+ caption: name,
+ content: command + ' ' + name
+ }));
+
+ let completions = [];
+ if (engineItems.length > 0) {
+ completions.push({
+ name: 'Search Engines',
+ items: engineItems
+ });
+ }
+ if (historyItems.length > 0) {
+ completions.push({
+ name: 'History',
+ items: historyItems
+ });
+ }
+ return completions;
+ });
+};
+
+const getCompletions = (line, settings) => {
+ let typedWords = line.trim().split(/ +/);
+ let typing = '';
+ if (!line.endsWith(' ')) {
+ typing = typedWords.pop();
+ }
+
+ if (typedWords.length === 0) {
+ return Promise.resolve([]);
+ }
+ let name = typedWords.shift();
+ let keywords = typedWords.concat(typing).join(' ');
+
+ switch (name) {
+ case 'o':
+ case 'open':
+ case 't':
+ case 'tabopen':
+ case 'w':
+ case 'winopen':
+ return getOpenCompletions(name, keywords, settings.search);
+ case 'b':
+ case 'buffer':
+ return tabs.getCompletions(keywords).then((gotTabs) => {
+ let items = gotTabs.map((tab) => {
+ return {
+ caption: tab.title,
+ content: name + ' ' + tab.title,
+ url: tab.url,
+ icon: tab.favIconUrl
+ };
+ });
+ return [
+ {
+ name: 'Buffers',
+ items: items
+ }
+ ];
+ });
+ }
+ return Promise.resolve([]);
+};
+
+const complete = (line, settings) => {
+ return getCompletions(line, settings);
+};
+
+export { complete };
diff --git a/src/background/shared/completions/tabs.js b/src/background/shared/completions/tabs.js
new file mode 100644
index 0000000..5edddca
--- /dev/null
+++ b/src/background/shared/completions/tabs.js
@@ -0,0 +1,10 @@
+const getCompletions = (keyword) => {
+ return browser.tabs.query({ currentWindow: true }).then((tabs) => {
+ let matched = tabs.filter((t) => {
+ return t.url.includes(keyword) || t.title && t.title.includes(keyword);
+ });
+ return matched;
+ });
+};
+
+export { getCompletions };
diff --git a/src/background/tabs.js b/src/background/shared/tabs.js
index e939870..277afb2 100644
--- a/src/background/tabs.js
+++ b/src/background/shared/tabs.js
@@ -66,15 +66,6 @@ const selectByKeyword = (current, keyword) => {
});
};
-const getCompletions = (keyword) => {
- return browser.tabs.query({ currentWindow: true }).then((tabs) => {
- let matched = tabs.filter((t) => {
- return t.url.includes(keyword) || t.title && t.title.includes(keyword);
- });
- return matched;
- });
-};
-
const selectPrevTab = (current, count) => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => {
if (tabs.length < 2) {
@@ -139,7 +130,7 @@ const duplicate = (id) => {
export {
closeTab, closeTabForce, reopenTab, selectAt, selectByKeyword,
- getCompletions, selectPrevTab, selectNextTab, selectFirstTab,
+ selectPrevTab, selectNextTab, selectFirstTab,
selectLastTab, selectPrevSelTab, reload, updateTabPinned,
toggleTabPinned, duplicate
};
diff --git a/src/background/zooms.js b/src/background/shared/zooms.js
index e3e2aa6..e3e2aa6 100644
--- a/src/background/zooms.js
+++ b/src/background/shared/zooms.js