Use 0-based index in tab positions (fixes #46)
This commit is contained in:
parent
15812d2e1f
commit
5fc15ab42b
5 changed files with 20 additions and 33 deletions
2
dist/electron-tabs.d.ts
vendored
2
dist/electron-tabs.d.ts
vendored
|
@ -81,7 +81,7 @@ export class Tab extends EventTarget {
|
|||
getBadge(): string;
|
||||
setIcon(iconURL: string, icon: string): this;
|
||||
getIcon(): string;
|
||||
setPosition(newPosition: number): this;
|
||||
setPosition(newPosition: number): void;
|
||||
getPosition(fromRight?: boolean): number;
|
||||
activate(): this;
|
||||
show(flag?: boolean): this;
|
||||
|
|
2
dist/electron-tabs.d.ts.map
vendored
2
dist/electron-tabs.d.ts.map
vendored
File diff suppressed because one or more lines are too long
17
dist/electron-tabs.js
vendored
17
dist/electron-tabs.js
vendored
|
@ -2831,18 +2831,16 @@ class $eda442ba39f881a8$var$Tab extends EventTarget {
|
|||
}
|
||||
setPosition(newPosition) {
|
||||
const tabContainer = this.tabGroup.tabContainer;
|
||||
const tabs = tabContainer.children;
|
||||
const oldPosition = this.getPosition() - 1;
|
||||
const length = tabContainer.childElementCount;
|
||||
const thisPosition = this.getPosition();
|
||||
const tabs = Array.from(tabContainer.children);
|
||||
tabs.splice(thisPosition, 1);
|
||||
if (newPosition < 0) {
|
||||
newPosition += tabContainer.childElementCount;
|
||||
newPosition += length;
|
||||
if (newPosition < 0) newPosition = 0;
|
||||
} else {
|
||||
if (newPosition > tabContainer.childElementCount) newPosition = tabContainer.childElementCount;
|
||||
// Make 1 be leftmost position
|
||||
newPosition--;
|
||||
}
|
||||
if (newPosition > oldPosition) newPosition++;
|
||||
tabContainer.insertBefore(tabs[oldPosition], tabs[newPosition]);
|
||||
if (newPosition < length) tabContainer.insertBefore(this.tab, tabs[newPosition]);
|
||||
else tabContainer.appendChild(this.tab);
|
||||
return this;
|
||||
}
|
||||
getPosition(fromRight = false) {
|
||||
|
@ -2850,7 +2848,6 @@ class $eda442ba39f881a8$var$Tab extends EventTarget {
|
|||
let tab = this.tab;
|
||||
while((tab = tab.previousSibling) != null)position++;
|
||||
if (fromRight === true) position -= this.tabGroup.tabContainer.childElementCount;
|
||||
if (position >= 0) position++;
|
||||
return position;
|
||||
}
|
||||
activate() {
|
||||
|
|
2
dist/electron-tabs.js.map
vendored
2
dist/electron-tabs.js.map
vendored
File diff suppressed because one or more lines are too long
30
src/index.ts
30
src/index.ts
|
@ -460,30 +460,24 @@ class Tab extends EventTarget {
|
|||
|
||||
setPosition(newPosition: number) {
|
||||
const tabContainer = this.tabGroup.tabContainer;
|
||||
const tabs = tabContainer.children;
|
||||
const oldPosition = this.getPosition() - 1;
|
||||
const length = tabContainer.childElementCount;
|
||||
const thisPosition = this.getPosition();
|
||||
const tabs = Array.from(tabContainer.children)
|
||||
tabs.splice(thisPosition, 1);
|
||||
|
||||
if (newPosition < 0) {
|
||||
newPosition += tabContainer.childElementCount;
|
||||
|
||||
newPosition += length;
|
||||
if (newPosition < 0) {
|
||||
newPosition = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (newPosition < length) {
|
||||
tabContainer.insertBefore(this.tab, tabs[newPosition]);
|
||||
} else {
|
||||
if (newPosition > tabContainer.childElementCount) {
|
||||
newPosition = tabContainer.childElementCount;
|
||||
}
|
||||
|
||||
// Make 1 be leftmost position
|
||||
newPosition--;
|
||||
tabContainer.appendChild(this.tab);
|
||||
}
|
||||
|
||||
if (newPosition > oldPosition) {
|
||||
newPosition++;
|
||||
}
|
||||
|
||||
tabContainer.insertBefore(tabs[oldPosition], tabs[newPosition]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -496,10 +490,6 @@ class Tab extends EventTarget {
|
|||
position -= this.tabGroup.tabContainer.childElementCount;
|
||||
}
|
||||
|
||||
if (position >= 0) {
|
||||
position++;
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue