Skip to content

Commit

Permalink
move logic to preventParentScroll util function
Browse files Browse the repository at this point in the history
  • Loading branch information
Oyku Yilmaz committed Dec 11, 2023
1 parent 62ae019 commit 0c19926
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
9 changes: 2 additions & 7 deletions 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 @@ -587,13 +588,7 @@ class Autocomplete {
this.tooltipNode.id = "doc-tooltip";
this.tooltipNode.setAttribute("role", "tooltip");
// prevent editor scroll if tooltip is inside an editor
this.tooltipNode.addEventListener("wheel", function(event) {
event.stopPropagation();
var contentOverflows = this.tooltipNode.scrollHeight > this.tooltipNode.clientHeight;
if (!contentOverflows) {
event.preventDefault();
}
}.bind(this));
this.tooltipNode.addEventListener("wheel", preventParentScroll);
}
var theme = this.editor.renderer.theme;
this.tooltipNode.className = "ace_tooltip ace_doc-tooltip " +
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
}
};
9 changes: 2 additions & 7 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand Down Expand Up @@ -191,13 +192,7 @@ class HoverTooltip extends Tooltip {
if (!el.contains(document.activeElement)) this.hide();
}.bind(this));

el.addEventListener("wheel", function(event) {
event.stopPropagation();
var contentOverflows = el.scrollHeight > el.clientHeight;
if (!contentOverflows) {
event.preventDefault();
}
});
el.addEventListener("wheel", preventParentScroll);
}

addToEditor(editor) {
Expand Down

0 comments on commit 0c19926

Please sign in to comment.