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

navigator: handle middle-click behavior #12783

Merged
merged 9 commits into from
Aug 3, 2023
28 changes: 28 additions & 0 deletions packages/core/src/browser/tree/tree-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
}),
]);
}
this.node.addEventListener('mousedown', this.handleMiddleClickEvent.bind(this));
this.node.addEventListener('mouseup', this.handleMiddleClickEvent.bind(this));
this.node.addEventListener('auxclick', this.handleMiddleClickEvent.bind(this));
this.toDispose.pushAll([
this.model,
this.model.onChanged(() => this.updateRows()),
Expand Down Expand Up @@ -924,6 +927,7 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
style,
onClick: event => this.handleClickEvent(node, event),
onDoubleClick: event => this.handleDblClickEvent(node, event),
onAuxClick: event => this.handleAuxClickEvent(node, event),
onContextMenu: event => this.handleContextMenuEvent(node, event),
};
}
Expand Down Expand Up @@ -1238,6 +1242,30 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
event.stopPropagation();
}

/**
* Handle the middle-click mouse event.
* @param node the tree node if available.
* @param event the middle-click mouse event.
*/
protected handleAuxClickEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void {
this.model.openNode(node);
if (SelectableTreeNode.is(node)) {
this.model.selectNode(node);
}
event.stopPropagation();
}

/**
* Handle the middle-click mouse event.
* @param event the middle-click mouse event.
*/
protected handleMiddleClickEvent(event: MouseEvent): void {
// Prevents auto-scrolling behavior when middle-clicking.
if (event.button === 1) {
event.preventDefault();
}
}

/**
* Handle the context menu click event.
* - The context menu click event is triggered by the right-click.
Expand Down
Loading