diff options
Diffstat (limited to 'src/actions')
-rw-r--r-- | src/actions/background.js | 11 | ||||
-rw-r--r-- | src/actions/command.js | 35 | ||||
-rw-r--r-- | src/actions/console.js | 28 | ||||
-rw-r--r-- | src/actions/index.js | 40 | ||||
-rw-r--r-- | src/actions/input.js | 15 |
5 files changed, 129 insertions, 0 deletions
diff --git a/src/actions/background.js b/src/actions/background.js new file mode 100644 index 0000000..40b901b --- /dev/null +++ b/src/actions/background.js @@ -0,0 +1,11 @@ +import actions from '../actions'; + +export function requestCompletions(line) { + let command = line.split(' ', 1)[0]; + let keywords = line.replace(command + ' ', ''); + return { + type: actions.BACKGROUND_REQUEST_COMPLETIONS, + command, + keywords + }; +} diff --git a/src/actions/command.js b/src/actions/command.js new file mode 100644 index 0000000..c983278 --- /dev/null +++ b/src/actions/command.js @@ -0,0 +1,35 @@ +import actions from '../actions'; + +const normalizeUrl = (string) => { + try { + return new URL(string).href + } catch (e) { + return 'http://' + string; + } +} + +export function exec(line) { + let name = line.split(' ')[0]; + let remaining = line.replace(name + ' ', ''); + + switch (name) { + case 'open': + // TODO use search engined and pass keywords to them + return { + type: actions.COMMAND_OPEN_URL, + url: normalizeUrl(remaining) + }; + case 'tabopen': + return { + type: actions.COMMAND_TABOPEN_URL, + url: normalizeUrl(remaining) + }; + case 'b': + case 'buffer': + return { + type: actions.COMMAND_BUFFER, + keywords: remaining + }; + } + throw new Error(name + ' command is not defined'); +} diff --git a/src/actions/console.js b/src/actions/console.js new file mode 100644 index 0000000..99a46e8 --- /dev/null +++ b/src/actions/console.js @@ -0,0 +1,28 @@ +import actions from '../actions'; + +export function showCommand(text) { + return { + type: actions.CONSOLE_SHOW_COMMAND, + text: text + }; +} + +export function setCompletions(completions) { + return { + type: actions.CONSOLE_SET_COMPLETIONS, + completions: completions + }; +} + +export function showError(text) { + return { + type: actions.CONSOLE_SHOW_ERROR, + text: text + }; +} + +export function hide() { + return { + type: actions.CONSOLE_HIDE + }; +} diff --git a/src/actions/index.js b/src/actions/index.js new file mode 100644 index 0000000..63d5f6f --- /dev/null +++ b/src/actions/index.js @@ -0,0 +1,40 @@ +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', + + // Background commands + BACKGROUND_REQUEST_COMPLETIONS: 'vimvixen.background.request.completions', + TABS_CLOSE: 'tabs.close', + TABS_REOPEN: 'tabs.reopen', + TABS_PREV: 'tabs.prev', + TABS_NEXT: 'tabs.next', + TABS_RELOAD: 'tabs.reload', + ZOOM_IN: 'zoom.in', + ZOOM_OUT: 'zoom.out', + ZOOM_NEUTRAL: 'zoom.neutral', + + // content commands + CMD_OPEN: 'cmd.open', + CMD_TABS_OPEN: 'cmd.tabs.open', + CMD_BUFFER: 'cmd.buffer', + SCROLL_LINES: 'scroll.lines', + SCROLL_PAGES: 'scroll.pages', + SCROLL_TOP: 'scroll.top', + SCROLL_BOTTOM: 'scroll.bottom', + SCROLL_LEFT: 'scroll.left', + SCROLL_RIGHT: 'scroll.right', + FOLLOW_START: 'follow.start', + HISTORY_PREV: 'history.prev', + HISTORY_NEXT: 'history.next', + + // User input + INPUT_KEY_PRESS: 'input.key,press', + INPUT_CLEAR_KEYS: 'input.clear.keys', + + COMMAND_OPEN_URL: 'command.open.url', + COMMAND_TABOPEN_URL: 'command.tabopen.url', + COMMAND_BUFFER: 'command.buffer', +}; diff --git a/src/actions/input.js b/src/actions/input.js new file mode 100644 index 0000000..c72b9e0 --- /dev/null +++ b/src/actions/input.js @@ -0,0 +1,15 @@ +import actions from '../actions'; + +export function keyPress(code, ctrl) { + return { + type: actions.INPUT_KEY_PRESS, + code, + ctrl + }; +} + +export function clearKeys() { + return { + type: actions.INPUT_CLEAR_KEYS + } +} |