Previous selected tab based on tab events only

jh-changes
Daniel Campoverde 7 years ago
parent 3acd921d52
commit 6fc5d06205
  1. 36
      src/background/tabs.js

@ -6,7 +6,6 @@ browser.tabs.onActivated.addListener(tabChangeHandler);
function tabChangeHandler(activeInfo) { function tabChangeHandler(activeInfo) {
prevSelTab = currSelTab; prevSelTab = currSelTab;
currSelTab = activeInfo.tabId; currSelTab = activeInfo.tabId;
console.log("prev tab: " + prevSelTab + " - curr tab: " + currSelTab);
} }
const closeTab = (id) => { const closeTab = (id) => {
@ -69,76 +68,43 @@ const getCompletions = (keyword) => {
}; };
const selectPrevTab = (current, count) => { const selectPrevTab = (current, count) => {
browser.tabs.query({ currentWindow: true, active: true }).then((tabs) => {
prevSelTab = tabs[0].id;
});
return browser.tabs.query({ currentWindow: true }).then((tabs) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => {
if (tabs.length < 2) { if (tabs.length < 2) {
return; return;
} }
let select = (current - count + tabs.length) % tabs.length; let select = (current - count + tabs.length) % tabs.length;
let id = tabs[select].id; let id = tabs[select].id;
currSelTab = id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
}); });
}; };
const selectNextTab = (current, count) => { const selectNextTab = (current, count) => {
browser.tabs.query({ currentWindow: true, active: true }).then((tabs) => {
prevSelTab = tabs[0].id;
});
return browser.tabs.query({ currentWindow: true }).then((tabs) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => {
if (tabs.length < 2) { if (tabs.length < 2) {
return; return;
} }
let select = (current + count) % tabs.length; let select = (current + count) % tabs.length;
let id = tabs[select].id; let id = tabs[select].id;
currSelTab = id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
}); });
}; };
const selectFirstTab = () => { const selectFirstTab = () => {
browser.tabs.query({ currentWindow: true, active: true }).then((tabs) => {
prevSelTab = tabs[0].id;
});
return browser.tabs.query({ currentWindow: true }).then((tabs) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => {
let id = tabs[0].id; let id = tabs[0].id;
currSelTab = id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
}); });
}; };
const selectLastTab = () => { const selectLastTab = () => {
browser.tabs.query({ currentWindow: true, active: true }).then((tabs) => {
prevSelTab = tabs[0].id;
});
return browser.tabs.query({ currentWindow: true }).then((tabs) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => {
let id = tabs[tabs.length - 1].id; let id = tabs[tabs.length - 1].id;
currSelTab = id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
}); });
}; };
// const selectPrevSelTab = () => {
// let tmpPrevSelTab = null;
// return browser.tabs.query({ currentWindow: true, active: true }).then(
// (tabs) => {
// tmpPrevSelTab = tabs[0].id;
// browser.tabs.update(prevSelTab, { active: true });
// prevSelTab = tmpPrevSelTab;
// });
// };
const selectPrevSelTab = () => { const selectPrevSelTab = () => {
let tmpPrevSelTab = prevSelTab; return browser.tabs.update(prevSelTab, { active: true });
prevSelTab = currSelTab;
currSelTab = tmpPrevSelTab;
return browser.tabs.update(currSelTab, { active: true });
}; };
const reload = (current, cache) => { const reload = (current, cache) => {