Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tab scrolling on tabbar #297

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement scrolling to active tab, fix styles, add release guard
krassowski committed Aug 3, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit de12bf88f1ba20c98e6e75b18e16b09b69d39e12
34 changes: 33 additions & 1 deletion packages/widgets/src/tabbar.ts
Original file line number Diff line number Diff line change
@@ -367,7 +367,7 @@ export class TabBar<T> extends Widget {
if (value) {
this.node.classList.add('lm-mod-scrollable');
} else {
this.node.classList.add('lm-mod-scrollable');
this.node.classList.remove('lm-mod-scrollable');
}
this.maybeSwitchScrollButtons();
}
@@ -694,14 +694,41 @@ export class TabBar<T> extends Widget {
content[i] = renderer.renderTab({ title, current, zIndex });
}
VirtualDOM.render(content, this.contentNode);

this.maybeSwitchScrollButtons();

// Scroll the current tab into view.
this.scrollCurrentIntoView();
}

protected onResize(msg: Widget.ResizeMessage): void {
super.onResize(msg);
this.maybeSwitchScrollButtons();
}

/**
* Scroll the current tab into view.
*/
protected scrollCurrentIntoView() {
if (this.scrollingEnabled) {
const contentNode = this.contentNode;
const currentNode = contentNode.children.item(this.currentIndex);
if (currentNode) {
currentNode.scrollIntoView();
if (this.orientation == 'horizontal') {
contentNode.scrollTop = 0;
} else {
contentNode.scrollLeft = 0;
}
} else {
console.error('Current tab node not found');
}
}
}

/**
* Show/hide scroll buttons if needed.
*/
protected maybeSwitchScrollButtons() {
const scrollBefore = this.scrollBeforeButtonNode;
const scrollAfter = this.scrollAfterButtonNode;
@@ -1152,6 +1179,11 @@ export class TabBar<T> extends Widget {
return;
}

// Do nothing if neither press nor release was on a tab.
if (index === -1 && data.index === -1) {
return;
}

// Ignore the release if the title is not closable.
let title = this._titles[index];
if (!title.closable) {
2 changes: 1 addition & 1 deletion packages/widgets/style/tabbar.css
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@
display: none !important;
}

.lm-TabBar-addButton.lm-mod-hidden {
.lm-TabBar-button.lm-mod-hidden {
display: none !important;
}