mirror of
https://ark.sudovanilla.org/Korbs/electron-tabs.git
synced 2024-12-22 19:43:53 +00:00
Add ability to get tabs by position as well as by id
This commit is contained in:
parent
fda4fbd612
commit
4e36e14679
29
index.js
29
index.js
|
@ -67,7 +67,15 @@ class TabGroup extends EventEmitter {
|
|||
return tab;
|
||||
}
|
||||
|
||||
getTab (id) {
|
||||
getTab (id, idIsPosition) {
|
||||
if (idIsPosition !== true) {
|
||||
return this.getTabById(id);
|
||||
} else {
|
||||
return this.getTabByPosition(id);
|
||||
}
|
||||
}
|
||||
|
||||
getTabById (id) {
|
||||
for (let i in this.tabs) {
|
||||
if (this.tabs[i].id === id) {
|
||||
return this.tabs[i];
|
||||
|
@ -76,6 +84,19 @@ class TabGroup extends EventEmitter {
|
|||
return null;
|
||||
}
|
||||
|
||||
getTabByPosition (position) {
|
||||
let fromRight = position < 0;
|
||||
if (position === 0) {
|
||||
position = 1;
|
||||
}
|
||||
for (let i in this.tabs) {
|
||||
if (this.tabs[i].getPosition(fromRight) === position) {
|
||||
return this.tabs[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getTabs () {
|
||||
return this.tabs;
|
||||
}
|
||||
|
@ -212,7 +233,7 @@ class Tab extends EventEmitter {
|
|||
setPosition (newPosition) {
|
||||
let tabContainer = this.tabGroup.tabContainer;
|
||||
let tabs = tabContainer.children;
|
||||
let oldPosition = this.getPosition();
|
||||
let oldPosition = this.getPosition() - 1;
|
||||
|
||||
if (newPosition < 0) {
|
||||
newPosition += tabContainer.childElementCount;
|
||||
|
@ -247,8 +268,8 @@ class Tab extends EventEmitter {
|
|||
position -= this.tabGroup.tabContainer.childElementCount;
|
||||
}
|
||||
|
||||
if (position === 0) {
|
||||
position = 1;
|
||||
if (position >= 0) {
|
||||
position++;
|
||||
}
|
||||
|
||||
return position;
|
||||
|
|
Loading…
Reference in a new issue