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 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
4 changes: 3 additions & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var dom = require("./lib/dom");
var snippetManager = require("./snippets").snippetManager;
var config = require("./config");
var event = require("./lib/event");
var preventParentScroll = require("./lib/scroll").preventParentScroll;

/**
* @typedef BaseCompletion
Expand Down Expand Up @@ -580,13 +581,14 @@ 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", preventParentScroll);
}
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
8 changes: 8 additions & 0 deletions src/lib/scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.preventParentScroll = function preventParentScroll(event) {
event.stopPropagation();
var target = event.currentTarget;
var contentOverflows = target.scrollHeight > target.clientHeight;
if (!contentOverflows) {
event.preventDefault();

Check warning on line 6 in src/lib/scroll.js

View check run for this annotation

Codecov / codecov/patch

src/lib/scroll.js#L2-L6

Added lines #L2 - L6 were not covered by tests
}
};
5 changes: 3 additions & 2 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
var dom = require("./lib/dom");
var event = require("./lib/event");
var Range = require("./range").Range;
var preventParentScroll = require("./lib/scroll").preventParentScroll;

var CLASSNAME = "ace_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
class Tooltip {
/**
* @param {Element} parentNode
Expand Down Expand Up @@ -190,8 +191,8 @@
el.addEventListener("blur", function() {
if (!el.contains(document.activeElement)) this.hide();
}.bind(this));
el.addEventListener("wheel", event.stopPropagation);

el.addEventListener("wheel", preventParentScroll);
}

addToEditor(editor) {
Expand Down
Loading