Fixed serchmode persistence and missing slot 0 tab

This commit is contained in:
2018-05-24 17:04:06 -05:00
parent da93d9cfc3
commit c70553b0e4
5 changed files with 70 additions and 27 deletions

View File

@@ -1,3 +1,4 @@
const storageArea = browser.storage.local;
const tabsAction = browser.tabs;
const searchBar = document.getElementById("searchBar");
const errHandler = document.getElementById("errorZone");
@@ -33,13 +34,14 @@ function logTabs(tabs) {
windowIndex++;
createContainer(tab);
} else {
createContainer(tab);
windowIndex = 1;
}
}
newWinId = currentWinId;
}
newWinId = undefined;
newWinId = undefined;
// Set poped-out-window position and 100px up from selected elm
oldElm.scrollIntoView();
window.scrollBy(0, -100);
@@ -84,7 +86,7 @@ function createContainer(tab) {
// Set oldElm so eventListeners.js has starting ref
if (tab.active == true) {
spanTag.className = "block block-focused";
spanTag.className = "block block-focused";
if (oldElm) {
oldElm.setAttribute("class", "block");
}
@@ -104,15 +106,49 @@ function createTab() {
function onError(error) { console.log(`Error: ${error}`); }
function getTabs() {
var elm = document.getElementById("searchMode");
var currentMode = (elm.getAttribute("searchwindowsmode") == "false");
clearNodes(listZone);
if (currentMode == false) {
tabsAction.query({}).then(logTabs, onError)
.then(resetWinIndex, onError);
} else {
tabsAction.query({currentWindow: currentMode})
.then(logTabs, onError)
storageArea.get("searchMode").then((results) => {
var target = document.getElementById("searchMode");
if (Object.keys(results).length > 0) {
var fileKeys = Object.keys(results);
for (let fileKey of fileKeys) {
var key = results[fileKey];
if (key) {
target.title = "Searching curent windows...";
target.children[0].src = "../icons/windows.png";
target.setAttribute("searchwindowsmode", true);
tabsAction.query({}).then(logTabs, onError)
.then(resetWinIndex, onError);
} else {
target.title = "Searching curent window...";
target.children[0].src = "../icons/window.png";
target.setAttribute("searchwindowsmode", false);
tabsAction.query({currentWindow: true})
.then(logTabs, onError);
}
}
} else {
setSearchMode(target, "curent window", "window", false);
}
});
}
async function setSearchMode(target, text, img, state) {
target.title = "Searching " + text + "...";
target.children[0].src = "../icons/" + img + ".png";
target.setAttribute("searchwindowsmode", state);
await storageArea.set({"searchMode": state });
getTabs(); // No loop b/c object keys will be greater than 0 after setup
}
function clearNodes(targetNode) {
while (targetNode.firstChild) {
targetNode.removeChild(targetNode.firstChild);
}
}