implement o/O command

jh-changes
Shin'ya Ueoka 7 years ago
parent 9a808f45ed
commit 36680ed8fe
  1. 6
      src/background/index.js
  2. 2
      src/background/key-queue.js
  3. 3
      src/content/footer-line.js
  4. 44
      src/content/index.js
  5. 2
      src/shared/actions.js

@ -36,7 +36,11 @@ const doBackgroundAction = (sender, action) => {
} }
const normalizeUrl = (string) => { const normalizeUrl = (string) => {
return 'http://' + string; try {
return new URL(string).href
} catch (e) {
return 'http://' + string;
}
} }
const cmdEnterHandle = (request, sender) => { const cmdEnterHandle = (request, sender) => {

@ -3,6 +3,8 @@ import * as actions from '../shared/actions';
const DEFAULT_KEYMAP = [ const DEFAULT_KEYMAP = [
{ keys: [{ code: KeyboardEvent.DOM_VK_SEMICOLON, shift: true }], action: [ actions.CMD_OPEN ]}, { keys: [{ code: KeyboardEvent.DOM_VK_SEMICOLON, shift: true }], action: [ actions.CMD_OPEN ]},
{ keys: [{ code: KeyboardEvent.DOM_VK_O }], action: [ actions.CMD_TABS_OPEN, false ]},
{ keys: [{ code: KeyboardEvent.DOM_VK_O, shift: true }], action: [ actions.CMD_TABS_OPEN, true ]},
{ keys: [{ code: KeyboardEvent.DOM_VK_K }], action: [ actions.SCROLL_UP, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_K }], action: [ actions.SCROLL_UP, 1 ]},
{ keys: [{ code: KeyboardEvent.DOM_VK_J }], action: [ actions.SCROLL_DOWN, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_J }], action: [ actions.SCROLL_DOWN, 1 ]},
{ keys: [{ code: KeyboardEvent.DOM_VK_G }, { code: KeyboardEvent.DOM_VK_G }], action: [ actions.SCROLL_TOP ]}, { keys: [{ code: KeyboardEvent.DOM_VK_G }, { code: KeyboardEvent.DOM_VK_G }], action: [ actions.SCROLL_TOP ]},

@ -1,7 +1,7 @@
import './footer-line.css'; import './footer-line.css';
export default class FooterLine { export default class FooterLine {
constructor(doc) { constructor(doc, initial = '') {
this.initUi(doc); this.initUi(doc);
this.enteredCallback = () => {} this.enteredCallback = () => {}
@ -10,6 +10,7 @@ export default class FooterLine {
this.input.addEventListener('blur', this.handleBlur.bind(this)); this.input.addEventListener('blur', this.handleBlur.bind(this));
this.input.addEventListener('keydown', this.handleKeydown.bind(this)); this.input.addEventListener('keydown', this.handleKeydown.bind(this));
this.input.addEventListener('keyup', this.handleKeyup.bind(this)); this.input.addEventListener('keyup', this.handleKeyup.bind(this));
this.input.value = initial;
} }
initUi(doc) { initUi(doc) {

@ -4,6 +4,25 @@ import * as actions from '../shared/actions';
var footer = null; var footer = null;
const createFooterLine = (initial = '') => {
footer = new FooterLine(document, initial);
footer.onPromptChange((e) => {
let request = {
type: 'event.cmd.suggest',
text: e.target.value
};
browser.runtime.sendMessage(request);
});
footer.onEntered((e) => {
let request = {
type: 'event.cmd.enter',
text: e.target.value
};
browser.runtime.sendMessage(request);
});
footer.focus();
}
const invokeEvent = (action) => { const invokeEvent = (action) => {
if (typeof action === 'undefined' || action === null) { if (typeof action === 'undefined' || action === null) {
return; return;
@ -11,22 +30,15 @@ const invokeEvent = (action) => {
switch (action[0]) { switch (action[0]) {
case actions.CMD_OPEN: case actions.CMD_OPEN:
footer = new FooterLine(document); createFooterLine();
footer.onPromptChange((e) => { break;
let request = { case actions.CMD_TABS_OPEN:
type: 'event.cmd.suggest', if (action[1] || false) {
text: e.target.value // alter url
}; createFooterLine('open ' + window.location.href);
browser.runtime.sendMessage(request); } else {
}); createFooterLine('open ');
footer.onEntered((e) => { }
let request = {
type: 'event.cmd.enter',
text: e.target.value
};
browser.runtime.sendMessage(request);
});
footer.focus();
break; break;
case actions.SCROLL_UP: case actions.SCROLL_UP:
scrolls.scrollUp(window, action[1] || 1); scrolls.scrollUp(window, action[1] || 1);

@ -1,4 +1,5 @@
export const CMD_OPEN = 'cmd.open'; export const CMD_OPEN = 'cmd.open';
export const CMD_TABS_OPEN = 'cmd.tabs.open';
export const TABS_PREV = 'tabs.prev'; export const TABS_PREV = 'tabs.prev';
export const TABS_NEXT = 'tabs.next'; export const TABS_NEXT = 'tabs.next';
export const SCROLL_UP = 'scroll.up'; export const SCROLL_UP = 'scroll.up';
@ -13,6 +14,7 @@ const BACKGROUND_ACTION_SET = new Set([
const CONTENT_ACTION_SET = new Set([ const CONTENT_ACTION_SET = new Set([
CMD_OPEN, CMD_OPEN,
CMD_TABS_OPEN,
SCROLL_UP, SCROLL_UP,
SCROLL_DOWN, SCROLL_DOWN,
SCROLL_TOP, SCROLL_TOP,