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;
|
getBadge(): string;
|
||||||
setIcon(iconURL: string, icon: string): this;
|
setIcon(iconURL: string, icon: string): this;
|
||||||
getIcon(): string;
|
getIcon(): string;
|
||||||
setPosition(newPosition: number): this;
|
setPosition(newPosition: number): void;
|
||||||
getPosition(fromRight?: boolean): number;
|
getPosition(fromRight?: boolean): number;
|
||||||
activate(): this;
|
activate(): this;
|
||||||
show(flag?: boolean): 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) {
|
setPosition(newPosition) {
|
||||||
const tabContainer = this.tabGroup.tabContainer;
|
const tabContainer = this.tabGroup.tabContainer;
|
||||||
const tabs = tabContainer.children;
|
const length = tabContainer.childElementCount;
|
||||||
const oldPosition = this.getPosition() - 1;
|
const thisPosition = this.getPosition();
|
||||||
|
const tabs = Array.from(tabContainer.children);
|
||||||
|
tabs.splice(thisPosition, 1);
|
||||||
if (newPosition < 0) {
|
if (newPosition < 0) {
|
||||||
newPosition += tabContainer.childElementCount;
|
newPosition += length;
|
||||||
if (newPosition < 0) newPosition = 0;
|
if (newPosition < 0) newPosition = 0;
|
||||||
} else {
|
|
||||||
if (newPosition > tabContainer.childElementCount) newPosition = tabContainer.childElementCount;
|
|
||||||
// Make 1 be leftmost position
|
|
||||||
newPosition--;
|
|
||||||
}
|
}
|
||||||
if (newPosition > oldPosition) newPosition++;
|
if (newPosition < length) tabContainer.insertBefore(this.tab, tabs[newPosition]);
|
||||||
tabContainer.insertBefore(tabs[oldPosition], tabs[newPosition]);
|
else tabContainer.appendChild(this.tab);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
getPosition(fromRight = false) {
|
getPosition(fromRight = false) {
|
||||||
|
@ -2850,7 +2848,6 @@ class $eda442ba39f881a8$var$Tab extends EventTarget {
|
||||||
let tab = this.tab;
|
let tab = this.tab;
|
||||||
while((tab = tab.previousSibling) != null)position++;
|
while((tab = tab.previousSibling) != null)position++;
|
||||||
if (fromRight === true) position -= this.tabGroup.tabContainer.childElementCount;
|
if (fromRight === true) position -= this.tabGroup.tabContainer.childElementCount;
|
||||||
if (position >= 0) position++;
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
activate() {
|
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) {
|
setPosition(newPosition: number) {
|
||||||
const tabContainer = this.tabGroup.tabContainer;
|
const tabContainer = this.tabGroup.tabContainer;
|
||||||
const tabs = tabContainer.children;
|
const length = tabContainer.childElementCount;
|
||||||
const oldPosition = this.getPosition() - 1;
|
const thisPosition = this.getPosition();
|
||||||
|
const tabs = Array.from(tabContainer.children)
|
||||||
|
tabs.splice(thisPosition, 1);
|
||||||
|
|
||||||
if (newPosition < 0) {
|
if (newPosition < 0) {
|
||||||
newPosition += tabContainer.childElementCount;
|
newPosition += length;
|
||||||
|
|
||||||
if (newPosition < 0) {
|
if (newPosition < 0) {
|
||||||
newPosition = 0;
|
newPosition = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPosition < length) {
|
||||||
|
tabContainer.insertBefore(this.tab, tabs[newPosition]);
|
||||||
} else {
|
} else {
|
||||||
if (newPosition > tabContainer.childElementCount) {
|
tabContainer.appendChild(this.tab);
|
||||||
newPosition = tabContainer.childElementCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make 1 be leftmost position
|
|
||||||
newPosition--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newPosition > oldPosition) {
|
|
||||||
newPosition++;
|
|
||||||
}
|
|
||||||
|
|
||||||
tabContainer.insertBefore(tabs[oldPosition], tabs[newPosition]);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,10 +490,6 @@ class Tab extends EventTarget {
|
||||||
position -= this.tabGroup.tabContainer.childElementCount;
|
position -= this.tabGroup.tabContainer.childElementCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position >= 0) {
|
|
||||||
position++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue