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

Pass Tabbar DOM events to the Widget #9511

Open
colin-grant-work opened this issue May 24, 2021 · 0 comments
Open

Pass Tabbar DOM events to the Widget #9511

colin-grant-work opened this issue May 24, 2021 · 0 comments
Labels
core issues related to the core of the application proposal feature proposals (potential future features)

Comments

@colin-grant-work
Copy link
Contributor

colin-grant-work commented May 24, 2021

Feature Description:

It would be nice if widgets could define handlers for events targeting the titles they own. The use case I have top of mind is converting an editor preview widget to a normal editor widget (#5757), but other use cases could no doubt be found.

In our tabbar implementation, we define some handlers to be called on various DOM events:

renderTab(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement {
const title = data.title;
const id = this.createTabId(data.title);
const key = this.createTabKey(data);
const style = this.createTabStyle(data);
const className = this.createTabClass(data);
const dataset = this.createTabDataset(data);
return h.li(
{
key, className, id, title: title.caption, style, dataset,
oncontextmenu: this.handleContextMenuEvent,
ondblclick: this.handleDblClickEvent,
onauxclick: (e: MouseEvent) => {
// If user closes the tab using mouse wheel, nothing should be pasted to an active editor
e.preventDefault();
}
},
h.div(
{ className: 'theia-tab-icon-label' },
this.renderIcon(data, isInSidePanel),
this.renderLabel(data, isInSidePanel),
this.renderBadge(data, isInSidePanel)
),
this.renderCloseIcon(data)
);
}

We could generalize that pattern, and do something like:

if (title.owner instanceof Widget && title.owner.handleTabDblClick) {
    // follow the convention that returning `false` prevents further work on the event
    const terminateHandling = title.owner.handleTabDblClick(e) === false || e.defaultPrevented;
    if (terminateHandling) return !terminateHandling;
}
// ... default code to run
@colin-grant-work colin-grant-work added proposal feature proposals (potential future features) core issues related to the core of the application labels May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core issues related to the core of the application proposal feature proposals (potential future features)
Projects
None yet
Development

No branches or pull requests

1 participant