Skip to content

Fix hover stuttering. #11675

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

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions news/2 Fixes/11422.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hover on notebooks or interactive window seems to stutter.
36 changes: 26 additions & 10 deletions src/datascience-ui/react-common/monacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -709,14 +709,18 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
}
};

private onHoverLeave = () => {
private onHoverLeave = (e: MouseEvent) => {
// If the hover is active, make sure to hide it.
if (this.state.editor && this.widgetParent) {
this.enteredHover = false;
// tslint:disable-next-line: no-any
const hover = this.state.editor.getContribution('editor.contrib.hover') as any;
if (hover._hideWidgets) {
hover._hideWidgets();

// Hide only if not still inside the same editor. Monaco will handle closing otherwise
if (!this.coordsInsideEditor(e.clientX, e.clientY)) {
// tslint:disable-next-line: no-any
const hover = this.state.editor.getContribution('editor.contrib.hover') as any;
if (hover._hideWidgets) {
hover._hideWidgets();
}
}
}
};
Expand All @@ -728,25 +732,37 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
}
};

private outermostParentLeave = () => {
// tslint:disable-next-line: no-any
private outermostParentLeave = (e: any) => {
// Have to bounce this because the leave for the cell is the
// enter for the hover
if (this.leaveTimer) {
clearTimeout(this.leaveTimer);
}
this.leaveTimer = window.setTimeout(this.outermostParentLeaveBounced, 0);
this.leaveTimer = window.setTimeout(() => this.outermostParentLeaveBounced(e), 0);
};

private outermostParentLeaveBounced = () => {
if (this.state.editor && !this.enteredHover) {
// tslint:disable-next-line: no-any
private outermostParentLeaveBounced = (e: MouseEvent) => {
if (this.state.editor && !this.enteredHover && !this.coordsInsideEditor(e.clientX, e.clientY)) {
// If we haven't already entered hover, then act like it shuts down
this.onHoverLeave();
this.onHoverLeave(e);
// Possible user is viewing the parameter hints, wait before user moves the mouse.
// Waiting for 1s is too long to move the mouse and hide the hints (100ms seems like a good fit).
setTimeout(() => this.hideParameterWidget(), 100);
}
};

private coordsInsideEditor(x: number, y: number): boolean {
if (this.monacoContainer) {
const clientRect = this.monacoContainer.getBoundingClientRect();
if (x >= clientRect.left && x <= clientRect.right && y >= clientRect.top && y <= clientRect.bottom) {
return true;
}
}
return false;
}

/**
* This will hide the parameter widget if the user is not hovering over
* the parameter widget for this monaco editor.
Expand Down