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

fix: prevent browser scroll while scrolling over the tooltip #5414

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 8 additions & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,20 @@ class Autocomplete {
this.tooltipNode = dom.createElement("div");
this.tooltipNode.style.margin = 0;
this.tooltipNode.style.pointerEvents = "auto";
this.tooltipNode.style.overscrollBehavior = "contain";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for doc-tooltips of autocomplete items, they are also scrollable.

this.tooltipNode.tabIndex = -1;
this.tooltipNode.onblur = this.blurListener.bind(this);
this.tooltipNode.onclick = this.onTooltipClick.bind(this);
this.tooltipNode.id = "doc-tooltip";
this.tooltipNode.setAttribute("role", "tooltip");
// prevent editor scroll if tooltip is inside an editor
this.tooltipNode.addEventListener("wheel", event.stopPropagation);
this.tooltipNode.addEventListener("wheel", function(event) {
event.stopPropagation();
var contentOverflows = this.tooltipNode.scrollHeight > this.tooltipNode.clientHeight;
if (!contentOverflows) {
event.preventDefault();
}
}.bind(this));
}
var theme = this.editor.renderer.theme;
this.tooltipNode.className = "ace_tooltip ace_doc-tooltip " +
Expand Down
1 change: 1 addition & 0 deletions src/css/editor-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ module.exports = `
pointer-events: none;
overflow: auto;
max-width: min(60em, 66vw);
overscroll-behavior: contain;
}
.ace_tooltip pre {
white-space: pre-wrap;
Expand Down
10 changes: 8 additions & 2 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

var CLASSNAME = "ace_tooltip";

class Tooltip {

Check warning on line 9 in src/tooltip.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'event' is assigned a value but never used
/**
* @param {Element} parentNode
**/
Expand Down Expand Up @@ -190,8 +190,14 @@
el.addEventListener("blur", function() {
if (!el.contains(document.activeElement)) this.hide();
}.bind(this));

el.addEventListener("wheel", event.stopPropagation);

el.addEventListener("wheel", function(event) {
event.stopPropagation();
var contentOverflows = el.scrollHeight > el.clientHeight;
if (!contentOverflows) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use event.target here, rename this function to something like preventParentScroll move to lib and use in both places?

event.preventDefault();
}
});
}

addToEditor(editor) {
Expand Down
Loading