You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

90 lines
2.2 KiB

import * as scrolls from './scrolls';
import * as histories from './histories';
import * as actions from '../shared/actions';
import ConsoleFrame from '../console/console-frame';
import Follow from './follow';
7 years ago
let vvConsole = new ConsoleFrame(window);
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
case actions.CMD_OPEN:
return vvConsole.showCommand('');
case actions.CMD_TABS_OPEN:
if (action.alter) {
// alter url
return vvConsole.showCommand('open ' + window.location.href);
} else {
return vvConsole.showCommand('open ');
}
case actions.CMD_BUFFER:
return vvConsole.showCommand('buffer ');
case actions.SCROLL_LINES:
scrolls.scrollLines(window, action.count);
break;
7 years ago
case actions.SCROLL_PAGES:
scrolls.scrollPages(window, action.count);
7 years ago
break;
case actions.SCROLL_TOP:
scrolls.scrollTop(window);
break;
case actions.SCROLL_BOTTOM:
scrolls.scrollBottom(window);
break;
case actions.SCROLL_LEFT:
scrolls.scrollLeft(window);
break;
case actions.SCROLL_RIGHT:
scrolls.scrollRight(window);
break;
case actions.FOLLOW_START:
new Follow(window.document, action.newTab);
break;
case actions.HISTORY_PREV:
histories.prev(window);
break;
case actions.HISTORY_NEXT:
histories.next(window);
break;
}
return Promise.resolve();
});
7 years ago
7 years ago
window.addEventListener("keypress", (e) => {
if (e.target instanceof HTMLInputElement) {
return;
}
let request = {
7 years ago
type: 'event.keypress',
code: e.which,
ctrl: e.ctrlKey,
}
browser.runtime.sendMessage(request)
7 years ago
.catch((err) => {
console.error("Vim Vixen:", err);
vvConsole.showError(err.message);
7 years ago
});
});
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
case 'vimvixen.command.blur':
if (!vvConsole.isErrorShown()) {
vvConsole.hide();
}
return Promise.resolve();
case 'vimvixen.command.enter':
return browser.runtime.sendMessage({
type: 'event.cmd.enter',
text: action.value
7 years ago
}).catch((err) => {
console.error("Vim Vixen:", err);
7 years ago
vvConsole.showError(err.message);
});
default:
return Promise.resolve();
}
});