Open adjacent tabs and background tabs

jh-changes
Erwan Ameil 7 years ago
parent a50c7dd0a2
commit 177940981e
  1. 6
      src/background/actions/tab.js
  2. 3
      src/background/components/background.js
  3. 3
      src/content/actions/follow-controller.js
  4. 3
      src/content/actions/operation.js
  5. 8
      src/content/components/common/follow.js
  6. 3
      src/content/components/top-content/follow-controller.js
  7. 2
      src/content/reducers/follow-controller.js
  8. 20
      src/shared/commands.js
  9. 7
      src/shared/default-settings.js
  10. 2
      src/shared/validators/setting.js

@ -1,9 +1,5 @@
const openNewTab = (url) => {
return browser.tabs.create({ url: url });
};
const openToTab = (url, tab) => { const openToTab = (url, tab) => {
return browser.tabs.update(tab.id, { url: url }); return browser.tabs.update(tab.id, { url: url });
}; };
export { openToTab, openNewTab }; export { openToTab };

@ -30,7 +30,8 @@ export default class BackgroundComponent {
case messages.OPEN_URL: case messages.OPEN_URL:
if (message.newTab) { if (message.newTab) {
return this.store.dispatch( return this.store.dispatch(
tabActions.openNewTab(message.url), sender); commands.tabopenCommand(message.url, message.background,
settings.value.openAdjacentTabs), sender);
} }
return this.store.dispatch( return this.store.dispatch(
tabActions.openToTab(message.url, sender.tab), sender); tabActions.openToTab(message.url, sender.tab), sender);

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

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

@ -34,6 +34,7 @@ export default class Follow {
this.win = win; this.win = win;
this.store = store; this.store = store;
this.newTab = false; this.newTab = false;
this.background = false;
this.hints = {}; this.hints = {};
this.targets = []; this.targets = [];
@ -68,6 +69,7 @@ export default class Follow {
type: messages.OPEN_URL, type: messages.OPEN_URL,
url: element.href, url: element.href,
newTab: true, newTab: true,
background: this.background,
}); });
} }
@ -79,12 +81,13 @@ export default class Follow {
}), '*'); }), '*');
} }
createHints(keysArray, newTab) { createHints(keysArray, newTab, background) {
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.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];
@ -150,7 +153,8 @@ 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(message.keysArray, message.newTab); return this.createHints(
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:

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

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

@ -33,8 +33,19 @@ const openCommand = (url) => {
}); });
}; };
const tabopenCommand = (url) => { const tabopenCommand = (url, background = false, adjacent = false) => {
return browser.tabs.create({ url: url }); if (adjacent) {
return browser.tabs.query({
active: true, currentWindow: true
}).then((gotTabs) => {
return browser.tabs.create({
url: url,
active: !background,
index: gotTabs[0].index + 1
});
});
}
return browser.tabs.create({ url: url, active: !background });
}; };
const winopenCommand = (url) => { const winopenCommand = (url) => {
@ -102,7 +113,8 @@ const doCommand = (line, settings) => {
return openCommand(normalizeUrl(words, settings.search)); return openCommand(normalizeUrl(words, settings.search));
case 't': case 't':
case 'tabopen': case 'tabopen':
return tabopenCommand(normalizeUrl(words, settings.search)); return tabopenCommand(
normalizeUrl(words, settings.search), false, settings.openAdjacentTabs);
case 'w': case 'w':
case 'winopen': case 'winopen':
return winopenCommand(normalizeUrl(words, settings.search)); return winopenCommand(normalizeUrl(words, settings.search));
@ -166,4 +178,4 @@ const complete = (line, settings) => {
return getCompletions(line, settings); return getCompletions(line, settings);
}; };
export { exec, complete }; export { exec, complete, tabopenCommand };

@ -37,8 +37,8 @@ export default {
"zi": { "type": "zoom.in" }, "zi": { "type": "zoom.in" },
"zo": { "type": "zoom.out" }, "zo": { "type": "zoom.out" },
"zz": { "type": "zoom.neutral" }, "zz": { "type": "zoom.neutral" },
"f": { "type": "follow.start", "newTab": false }, "f": { "type": "follow.start", "newTab": false, "background": false },
"F": { "type": "follow.start", "newTab": true }, "F": { "type": "follow.start", "newTab": true, "background": false },
"H": { "type": "navigate.history.prev" }, "H": { "type": "navigate.history.prev" },
"L": { "type": "navigate.history.next" }, "L": { "type": "navigate.history.next" },
"[[": { "type": "navigate.link.prev" }, "[[": { "type": "navigate.link.prev" },
@ -61,6 +61,7 @@ export default {
"twitter": "https://twitter.com/search?q={}", "twitter": "https://twitter.com/search?q={}",
"wikipedia": "https://en.wikipedia.org/w/index.php?search={}" "wikipedia": "https://en.wikipedia.org/w/index.php?search={}"
} }
} },
"openAdjacentTabs": false
}` }`
}; };

@ -1,6 +1,6 @@
import operations from 'shared/operations'; import operations from 'shared/operations';
const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist']; const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'openAdjacentTabs'];
const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => { const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => {
return operations[key]; return operations[key];
}); });