Send properties on activate

jh-changes
Shin'ya Ueoka 6 years ago
parent fb8b4d28ce
commit 17dc2bb5ec
  1. 21
      src/content/components/common/follow.ts
  2. 2
      src/content/components/top-content/follow-controller.ts
  3. 4
      src/shared/messages.ts

@ -68,18 +68,12 @@ const isAriaHiddenOrAriaDisabled = (win: Window, element: Element): boolean => {
export default class Follow { export default class Follow {
private win: Window; private win: Window;
private newTab: boolean;
private background: boolean;
private hints: {[key: string]: Hint }; private hints: {[key: string]: Hint };
private targets: HTMLElement[] = []; private targets: HTMLElement[] = [];
constructor(win: Window) { constructor(win: Window) {
this.win = win; this.win = win;
this.newTab = false;
this.background = false;
this.hints = {}; this.hints = {};
this.targets = []; this.targets = [];
@ -106,13 +100,11 @@ export default class Follow {
}), '*'); }), '*');
} }
createHints(keysArray: string[], newTab: boolean, background: boolean) { createHints(keysArray: string[]) {
if (keysArray.length !== this.targets.length) { if (keysArray.length !== this.targets.length) {
throw new Error('illegal hint count'); throw new Error('illegal hint count');
} }
this.newTab = newTab;
this.background = background;
this.hints = {}; this.hints = {};
for (let i = 0; i < keysArray.length; ++i) { for (let i = 0; i < keysArray.length; ++i) {
let keys = keysArray[i]; let keys = keysArray[i];
@ -141,7 +133,7 @@ export default class Follow {
this.targets = []; this.targets = [];
} }
async activateHints(keys: string): Promise<void> { async activateHints(keys: string, newTab: boolean, background: boolean): Promise<void> {
let hint = this.hints[keys]; let hint = this.hints[keys];
if (!hint) { if (!hint) {
return; return;
@ -150,7 +142,7 @@ export default class Follow {
if (hint instanceof LinkHint) { if (hint instanceof LinkHint) {
let url = hint.getLink(); let url = hint.getLink();
// ignore taget='_blank' // ignore taget='_blank'
if (!this.newTab && hint.getLinkTarget() !== '_blank') { if (!newTab && hint.getLinkTarget() !== '_blank') {
hint.click(); hint.click();
return; return;
} }
@ -158,7 +150,7 @@ export default class Follow {
if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) { if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) {
return; return;
} }
await tabsClient.openUrl(url, this.newTab, this.background); await tabsClient.openUrl(url, newTab, background);
} else if (hint instanceof InputHint) { } else if (hint instanceof InputHint) {
hint.activate(); hint.activate();
} }
@ -169,12 +161,11 @@ export default class Follow {
case messages.FOLLOW_REQUEST_COUNT_TARGETS: case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return this.countHints(sender, message.viewSize, message.framePosition); return this.countHints(sender, message.viewSize, message.framePosition);
case messages.FOLLOW_CREATE_HINTS: case messages.FOLLOW_CREATE_HINTS:
return this.createHints( return this.createHints(message.keysArray);
message.keysArray, message.newTab, message.background);
case messages.FOLLOW_SHOW_HINTS: case messages.FOLLOW_SHOW_HINTS:
return this.showHints(message.keys); return this.showHints(message.keys);
case messages.FOLLOW_ACTIVATE: case messages.FOLLOW_ACTIVATE:
return this.activateHints(message.keys); return this.activateHints(message.keys, message.newTab, message.background);
case messages.FOLLOW_REMOVE_HINTS: case messages.FOLLOW_REMOVE_HINTS:
return this.removeHints(); return this.removeHints();
} }

@ -87,6 +87,8 @@ export default class FollowController {
broadcastMessage(this.win, { broadcastMessage(this.win, {
type: messages.FOLLOW_ACTIVATE, type: messages.FOLLOW_ACTIVATE,
keys: this.state.keys as string, keys: this.state.keys as string,
newTab: this.state.newTab!!,
background: this.state.background!!,
}); });
} }

@ -109,8 +109,6 @@ export interface FollowResponseCountTargetsMessage {
export interface FollowCreateHintsMessage { export interface FollowCreateHintsMessage {
type: typeof FOLLOW_CREATE_HINTS; type: typeof FOLLOW_CREATE_HINTS;
keysArray: string[]; keysArray: string[];
newTab: boolean;
background: boolean;
} }
export interface FollowShowHintsMessage { export interface FollowShowHintsMessage {
@ -125,6 +123,8 @@ export interface FollowRemoveHintsMessage {
export interface FollowActivateMessage { export interface FollowActivateMessage {
type: typeof FOLLOW_ACTIVATE; type: typeof FOLLOW_ACTIVATE;
keys: string; keys: string;
newTab: boolean;
background: boolean;
} }
export interface FollowKeyPressMessage { export interface FollowKeyPressMessage {