Fixed auto-scroll into view of currently selected tab.

This commit is contained in:
Maxim Stewart 2019-02-10 04:15:12 -06:00
parent 7feec057a5
commit 5afaf1d6a0
4 changed files with 18 additions and 15 deletions

View File

@ -4,9 +4,9 @@ Search Firefox tabs and get a list or automatic direct to the searched tab.
# Download # Download
https://addons.mozilla.org/en-US/firefox/addon/tab-search-and-manage/ https://addons.mozilla.org/en-US/firefox/addon/tab-search-and-manage/
# Version: 1.2.9 # Version: 1.3.0
<ul> <ul>
<li>Fixed window selection issue.</li> <li>Fixed auto-scroll into view of currently selected tab.</li>
</ul> </ul>
***Note: ***Note:

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Tab Search and Manage", "name": "Tab Search and Manage",
"version": "1.2.9", "version": "1.3.0",
"description": "This plugin can search, drag-n-drop ordering, and (un)hide all or some tabs.", "description": "This plugin can search, drag-n-drop ordering, and (un)hide all or some tabs.",
"applications": { "applications": {

View File

@ -4,7 +4,7 @@ document.getElementById("searchBar").onkeypress = function () {
// Set click events for tab blocks // Set click events for tab blocks
document.addEventListener("click", (e) => { document.addEventListener("click", (e) => {
var target = (!e.target.className.includes("pTagTitleText")) ? e.target : e.target.parentElement; var target = (!e.target.className.includes("pTagTitleText")) ? e.target : e.target.parentElement;
var targetID = target.id; var targetID = target.id;
var parentElm = target.parentElement; var parentElm = target.parentElement;
var id = 0; var id = 0;
@ -18,9 +18,7 @@ document.addEventListener("click", (e) => {
} else if (targetID == "goBottom") { } else if (targetID == "goBottom") {
window.scrollTo(0, document.body.scrollHeight); window.scrollTo(0, document.body.scrollHeight);
} else if (targetID == "goToTab") { } else if (targetID == "goToTab") {
// Go to selected and 100px up scrollToView(200);
oldElm.scrollIntoView();
window.scrollBy(0, -100);
} else if (targetID == "newTab") { } else if (targetID == "newTab") {
createTab(); createTab();
} else if (targetID == "hideTgglBttn") { } else if (targetID == "hideTgglBttn") {
@ -34,7 +32,7 @@ document.addEventListener("click", (e) => {
} }
}); });
function closeBttnAction(var target, var targetID, var parentElm, var id) { function closeBttnAction(target, targetID, parentElm, id) {
if (parentElm == oldElm) { if (parentElm == oldElm) {
var index = Array.from(parentElm.parentElement.children).indexOf(parentElm); var index = Array.from(parentElm.parentElement.children).indexOf(parentElm);
(index - 1 < 0) ? index++ : index-- ; // Check what index to chose (index - 1 < 0) ? index++ : index-- ; // Check what index to chose
@ -51,7 +49,7 @@ function closeBttnAction(var target, var targetID, var parentElm, var id) {
parentElm.parentElement.removeChild(parentElm); parentElm.parentElement.removeChild(parentElm);
} }
function setNewTabAction(var target, var targetID, var parentElm, var id) { function setNewTabAction(target, targetID, parentElm, id) {
id = parseInt(target.getAttribute("tabID")); id = parseInt(target.getAttribute("tabID"));
tabsAction.get(id).then((tab) => { tabsAction.get(id).then((tab) => {
browser.windows.update(tab.windowId, {focused: true}); browser.windows.update(tab.windowId, {focused: true});
@ -61,7 +59,7 @@ function setNewTabAction(var target, var targetID, var parentElm, var id) {
setOldElm(target); setOldElm(target);
} }
function hideSelectedTabAction(var target, var targetID, var parentElm, var id) { function hideSelectedTabAction(target, targetID, parentElm, id) {
id = parseInt(parentElm.getAttribute("tabID")); id = parseInt(parentElm.getAttribute("tabID"));
if (id != oldElm.getAttribute("tabID")) { if (id != oldElm.getAttribute("tabID")) {
@ -77,7 +75,7 @@ function hideSelectedTabAction(var target, var targetID, var parentElm, var id)
} }
} }
function setSearchModeAction(var target, var targetID, var parentElm, var id) { function setSearchModeAction(target, targetID, parentElm, id) {
var currentMode = target.getAttribute("searchwindowsmode"); var currentMode = target.getAttribute("searchwindowsmode");
if (currentMode == "true") { if (currentMode == "true") {
// In generateview // In generateview
@ -94,3 +92,11 @@ function setOldElm(target) {
oldElm = target; oldElm = target;
target.setAttribute("class", "block block-focused"); target.setAttribute("class", "block block-focused");
} }
function scrollToView(time) {
setTimeout(function () {
// Go to selected and 100px up
oldElm.scrollIntoView();
window.scrollBy(0, -100);
}, time);
}

View File

@ -16,7 +16,6 @@ function logTabs(tabs) {
windowIndex = 0; windowIndex = 0;
tabsAction.query({currentWindow: true, active: true}).then((tab) => { tabsAction.query({currentWindow: true, active: true}).then((tab) => {
console.log(tab);
focusedWinID = tab[0].windowId; focusedWinID = tab[0].windowId;
}, focusedWinID).then(() => { }, focusedWinID).then(() => {
for (let tab of tabs) { for (let tab of tabs) {
@ -44,9 +43,7 @@ function logTabs(tabs) {
}); });
newWinId = undefined; newWinId = undefined;
// Set poped-out-window position and 100px up from selected elm scrollToView(800);
oldElm.scrollIntoView();
window.scrollBy(0, -100);
} }
function createContainer(tab) { function createContainer(tab) {