aboutsummaryrefslogtreecommitdiff
path: root/src/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions')
-rw-r--r--src/actions/command.js147
-rw-r--r--src/actions/completion.js22
-rw-r--r--src/actions/console.js28
-rw-r--r--src/actions/follow.js2
-rw-r--r--src/actions/index.js10
-rw-r--r--src/actions/input.js2
-rw-r--r--src/actions/operation.js28
-rw-r--r--src/actions/setting.js6
8 files changed, 49 insertions, 196 deletions
diff --git a/src/actions/command.js b/src/actions/command.js
deleted file mode 100644
index f578afd..0000000
--- a/src/actions/command.js
+++ /dev/null
@@ -1,147 +0,0 @@
-import * as tabs from '../background/tabs';
-import * as histories from '../background/histories';
-import * as consoleActions from './console';
-
-const normalizeUrl = (string, searchConfig) => {
- try {
- return new URL(string).href;
- } catch (e) {
- if (string.includes('.') && !string.includes(' ')) {
- return 'http://' + string;
- }
- let query = encodeURI(string);
- let template = searchConfig.engines[
- searchConfig.default
- ];
- for (let key in searchConfig.engines) {
- if (string.startsWith(key + ' ')) {
- query = encodeURI(string.replace(key + ' ', ''));
- template = searchConfig.engines[key];
- }
- }
- return template.replace('{}', query);
- }
-};
-
-const openCommand = (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((gotTabs) => {
- if (gotTabs.length > 0) {
- if (isNaN(keywords)) {
- return tabs.selectByKeyword(gotTabs[0], keywords);
- }
- let index = parseInt(keywords, 10) - 1;
- return tabs.selectAt(index);
- }
- });
-};
-
-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 doCommand = (name, remaining, settings) => {
- switch (name) {
- case 'o':
- case 'open':
- // TODO use search engined and pass keywords to them
- return openCommand(normalizeUrl(remaining, settings.search));
- case 't':
- case 'tabopen':
- return tabopenCommand(normalizeUrl(remaining, settings.search));
- case 'b':
- case 'buffer':
- return bufferCommand(remaining);
- }
- throw new Error(name + ' command is not defined');
-};
-
-const getCompletions = (command, keywords, settings) => {
- switch (command) {
- case 'o':
- case 'open':
- case 't':
- case 'tabopen':
- return getOpenCompletions(command, keywords, settings.search);
- case 'b':
- case 'buffer':
- return tabs.getCompletions(keywords).then((gotTabs) => {
- let items = gotTabs.map((tab) => {
- return {
- caption: tab.title,
- content: command + ' ' + tab.title,
- url: tab.url,
- icon: tab.favIconUrl
- };
- });
- return [
- {
- name: 'Buffers',
- items: items
- }
- ];
- });
- }
- return Promise.resolve([]);
-};
-
-const exec = (line, settings) => {
- let name = line.split(' ')[0];
- let remaining = line.replace(name + ' ', '');
- return doCommand(name, remaining, settings).then(() => {
- return consoleActions.hide();
- });
-};
-
-const complete = (line, settings) => {
- let command = line.split(' ', 1)[0];
- let keywords = line.replace(command + ' ', '');
- return getCompletions(command, keywords, settings)
- .then(consoleActions.setCompletions);
-};
-
-export { exec, complete };
diff --git a/src/actions/completion.js b/src/actions/completion.js
deleted file mode 100644
index 1ffb025..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 e0ec631..4183489 100644
--- a/src/actions/console.js
+++ b/src/actions/console.js
@@ -1,4 +1,4 @@
-import actions from '../actions';
+import actions from 'actions';
const showCommand = (text) => {
return {
@@ -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/follow.js b/src/actions/follow.js
index 7ab689e..708cd95 100644
--- a/src/actions/follow.js
+++ b/src/actions/follow.js
@@ -1,4 +1,4 @@
-import actions from '../actions';
+import actions from 'actions';
const enable = (newTab) => {
return {
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/actions/input.js b/src/actions/input.js
index 67788dd..61acb76 100644
--- a/src/actions/input.js
+++ b/src/actions/input.js
@@ -1,4 +1,4 @@
-import actions from '../actions';
+import actions from 'actions';
const asKeymapChars = (key, ctrl) => {
if (ctrl) {
diff --git a/src/actions/operation.js b/src/actions/operation.js
index 5b7f127..295fd4f 100644
--- a/src/actions/operation.js
+++ b/src/actions/operation.js
@@ -1,8 +1,14 @@
-import operations from '../operations';
-import messages from '../content/messages';
-import * as consoleActions from './console';
-import * as tabs from '../background/tabs';
-import * as zooms from '../background/zooms';
+import operations from 'shared/operations';
+import messages from 'content/messages';
+import * as tabs from 'background/tabs';
+import * as zooms from 'background/zooms';
+
+const sendConsoleShowCommand = (tab, command) => {
+ return browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_COMMAND,
+ command,
+ });
+};
const exec = (operation, tab) => {
switch (operation.type) {
@@ -23,21 +29,21 @@ const exec = (operation, tab) => {
case operations.ZOOM_NEUTRAL:
return zooms.neutral();
case operations.COMMAND_SHOW:
- return consoleActions.showCommand('');
+ return sendConsoleShowCommand(tab, '');
case operations.COMMAND_SHOW_OPEN:
if (operation.alter) {
// alter url
- return consoleActions.showCommand('open ' + tab.url);
+ return sendConsoleShowCommand(tab, 'open ' + tab.url);
}
- return consoleActions.showCommand('open ');
+ return sendConsoleShowCommand(tab, 'open ');
case operations.COMMAND_SHOW_TABOPEN:
if (operation.alter) {
// alter url
- return consoleActions.showCommand('tabopen ' + tab.url);
+ return sendConsoleShowCommand(tab, 'tabopen ' + tab.url);
}
- return consoleActions.showCommand('tabopen ');
+ return sendConsoleShowCommand(tab, 'tabopen ');
case operations.COMMAND_SHOW_BUFFER:
- return consoleActions.showCommand('buffer ');
+ return sendConsoleShowCommand(tab, 'buffer ');
default:
return browser.tabs.sendMessage(tab.id, {
type: messages.CONTENT_OPERATION,
diff --git a/src/actions/setting.js b/src/actions/setting.js
index 7898f06..2a47608 100644
--- a/src/actions/setting.js
+++ b/src/actions/setting.js
@@ -1,6 +1,6 @@
-import actions from '../actions';
-import messages from '../content/messages';
-import DefaultSettings from '../shared/default-settings';
+import actions from 'actions';
+import messages from 'content/messages';
+import DefaultSettings from 'shared/default-settings';
const load = () => {
return browser.storage.local.get('settings').then((value) => {