Merge pull request #171 from idlewan/background-adjacent-tabs

Open adjacent tabs and background tabs
jh-changes
Shin'ya Ueoka 7 years ago committed by GitHub
commit 89d6afecfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      README.md
  2. 18
      src/background/actions/tab.js
  3. 6
      src/background/components/background.js
  4. 3
      src/content/actions/follow-controller.js
  5. 3
      src/content/actions/operation.js
  6. 8
      src/content/components/common/follow.js
  7. 3
      src/content/components/top-content/follow-controller.js
  8. 2
      src/content/reducers/follow-controller.js
  9. 4
      src/shared/settings/default.js
  10. 2
      src/shared/settings/properties.js

@ -112,6 +112,15 @@ Set hint characters
:set hintchars=0123456789
```
##### 'adjacenttab' property
Open a new tab on adjacent of the current tab.
```
:set noadjacenttab " open a tab at last
:set adjacenttab " open a tab adjacently
```
### Search engines
Vim Vixen supports search by search engines like Google and Yahoo.

@ -1,9 +1,21 @@
const openNewTab = (url, openerTabId) => {
return browser.tabs.create({ url, openerTabId });
const openNewTab = (url, openerTabId, background = false, adjacent = false) => {
if (adjacent) {
return browser.tabs.query({
active: true, currentWindow: true
}).then((tabs) => {
return browser.tabs.create({
url,
openerTabId,
active: !background,
index: tabs[0].index + 1
});
});
}
return browser.tabs.create({ url, active: !background });
};
const openToTab = (url, tab) => {
return browser.tabs.update(tab.id, { url: url });
};
export { openToTab, openNewTab };
export { openNewTab, openToTab };

@ -33,8 +33,10 @@ export default class BackgroundComponent {
sender);
case messages.OPEN_URL:
if (message.newTab) {
return this.store.dispatch(
tabActions.openNewTab(message.url, sender.tab.id), sender);
let action = tabActions.openNewTab(
message.url, sender.tab.id, message.background,
settings.value.properties.adjacenttab);
return this.store.dispatch(action, sender);
}
return this.store.dispatch(
tabActions.openToTab(message.url, sender.tab), sender);

@ -1,9 +1,10 @@
import actions from 'content/actions';
const enable = (newTab) => {
const enable = (newTab, background) => {
return {
type: actions.FOLLOW_CONTROLLER_ENABLE,
newTab,
background,
};
};

@ -44,7 +44,8 @@ const exec = (operation, repeat, settings) => {
case operations.FOLLOW_START:
return window.top.postMessage(JSON.stringify({
type: messages.FOLLOW_START,
newTab: operation.newTab
newTab: operation.newTab,
background: operation.background,
}), '*');
case operations.NAVIGATE_HISTORY_PREV:
return navigates.historyPrev(window);

@ -50,6 +50,7 @@ export default class Follow {
this.win = win;
this.store = store;
this.newTab = false;
this.background = false;
this.hints = {};
this.targets = [];
@ -85,6 +86,7 @@ export default class Follow {
type: messages.OPEN_URL,
url: element.href,
newTab: true,
background: this.background,
});
}
@ -96,12 +98,13 @@ export default class Follow {
}), '*');
}
createHints(keysArray, newTab) {
createHints(keysArray, newTab, background) {
if (keysArray.length !== this.targets.length) {
throw new Error('illegal hint count');
}
this.newTab = newTab;
this.background = background;
this.hints = {};
for (let i = 0; i < keysArray.length; ++i) {
let keys = keysArray[i];
@ -167,7 +170,8 @@ export default class Follow {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return this.countHints(sender, message.viewSize, message.framePosition);
case messages.FOLLOW_CREATE_HINTS:
return this.createHints(message.keysArray, message.newTab);
return this.createHints(
message.keysArray, message.newTab, message.background);
case messages.FOLLOW_SHOW_HINTS:
return this.showHints(message.keys);
case messages.FOLLOW_ACTIVATE:

@ -28,7 +28,7 @@ export default class FollowController {
switch (message.type) {
case messages.FOLLOW_START:
return this.store.dispatch(
followControllerActions.enable(message.newTab));
followControllerActions.enable(message.newTab, message.background));
case messages.FOLLOW_RESPONSE_COUNT_TARGETS:
return this.create(message.count, sender);
case messages.FOLLOW_KEY_PRESS:
@ -129,6 +129,7 @@ export default class FollowController {
type: messages.FOLLOW_CREATE_HINTS,
keysArray: produced,
newTab: this.state.newTab,
background: this.state.background,
}), '*');
}

@ -3,6 +3,7 @@ import actions from 'content/actions';
const defaultState = {
enabled: false,
newTab: false,
background: false,
keys: '',
};
@ -12,6 +13,7 @@ export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
enabled: true,
newTab: action.newTab,
background: action.background,
keys: '',
});
case actions.FOLLOW_CONTROLLER_DISABLE:

@ -37,8 +37,8 @@ export default {
"zi": { "type": "zoom.in" },
"zo": { "type": "zoom.out" },
"zz": { "type": "zoom.neutral" },
"f": { "type": "follow.start", "newTab": false },
"F": { "type": "follow.start", "newTab": true },
"f": { "type": "follow.start", "newTab": false, "background": false },
"F": { "type": "follow.start", "newTab": true, "background": false },
"H": { "type": "navigate.history.prev" },
"L": { "type": "navigate.history.next" },
"[[": { "type": "navigate.link.prev" },

@ -5,12 +5,14 @@
const types = {
hintchars: 'string',
smoothscroll: 'boolean',
adjacenttab: 'boolean',
};
// describe default values of a property
const defaults = {
hintchars: 'abcdefghijklmnopqrstuvwxyz',
smoothscroll: false,
adjacenttab: true,
};
export { types, defaults };