Skip to content

Commit 18e692a

Browse files
committed
fix broken doc tooltip positioning logic
1 parent 9a5199b commit 18e692a

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

src/autocomplete.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -687,48 +687,46 @@ class Autocomplete {
687687

688688
var leftSize = rect.left;
689689
var rightSize = window.innerWidth - rect.right - scrollBarSize;
690-
var topSize = popup.isTopdown ? rect.top : window.innerHeight - scrollBarSize - rect.bottom;
690+
var topSize = popup.isTopdown ? window.innerHeight - scrollBarSize - rect.bottom : rect.top;
691691
var scores = [
692692
Math.min(rightSize / targetWidth, 1),
693693
Math.min(leftSize / targetWidth, 1),
694-
Math.min(topSize / targetHeight * 0.9),
694+
Math.min(topSize / targetHeight, 1) * 0.9,
695695
];
696696
var max = Math.max.apply(Math, scores);
697697
var tooltipStyle = tooltipNode.style;
698698
tooltipStyle.display = "block";
699699

700-
if (max == scores[0]) {
700+
if (max == scores[0] || scores[0] >= 1) {
701701
tooltipStyle.left = (rect.right + 1) + "px";
702702
tooltipStyle.right = "";
703703
tooltipStyle.maxWidth = targetWidth * max + "px";
704704
tooltipStyle.top = rect.top + "px";
705705
tooltipStyle.bottom = "";
706706
tooltipStyle.maxHeight = Math.min(window.innerHeight - scrollBarSize - rect.top, targetHeight) + "px";
707-
} else if (max == scores[1]) {
707+
} else if (max == scores[1] || scores[1] >= 1) {
708708
tooltipStyle.right = window.innerWidth - rect.left + "px";
709709
tooltipStyle.left = "";
710710
tooltipStyle.maxWidth = targetWidth * max + "px";
711711
tooltipStyle.top = rect.top + "px";
712712
tooltipStyle.bottom = "";
713713
tooltipStyle.maxHeight = Math.min(window.innerHeight - scrollBarSize - rect.top, targetHeight) + "px";
714714
} else if (max == scores[2]) {
715-
tooltipStyle.left = window.innerWidth - rect.left + "px";
716-
tooltipStyle.maxWidth = Math.min(targetWidth, window.innerWidth) + "px";
715+
tooltipStyle.left = rect.left + "px";
716+
tooltipStyle.right = "";
717+
tooltipStyle.maxWidth = Math.min(targetWidth, window.innerWidth - rect.left) + "px";
717718

718719
if (popup.isTopdown) {
719720
tooltipStyle.top = rect.bottom + "px";
720-
tooltipStyle.left = rect.left + "px";
721-
tooltipStyle.right = "";
722721
tooltipStyle.bottom = "";
723722
tooltipStyle.maxHeight = Math.min(window.innerHeight - scrollBarSize - rect.bottom, targetHeight) + "px";
724723
} else {
725-
tooltipStyle.top = popup.container.offsetTop - tooltipNode.offsetHeight + "px";
726-
tooltipStyle.left = rect.left + "px";
727-
tooltipStyle.right = "";
728-
tooltipStyle.bottom = "";
729-
tooltipStyle.maxHeight = Math.min(popup.container.offsetTop, targetHeight) + "px";
724+
tooltipStyle.top = "";
725+
tooltipStyle.bottom = (window.innerHeight - rect.top) + "px";
726+
tooltipStyle.maxHeight = Math.min(rect.top, targetHeight) + "px";
730727
}
731728
}
729+
dom.$fixPositionBug(tooltipNode);
732730
}
733731

734732
hideDocTooltip() {

src/autocomplete/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ class AcePopup {
389389

390390
el.style.left = left + "px";
391391
el.style.right = "";
392+
dom.$fixPositionBug(el);
392393

393394
if (!popup.isOpen) {
394395
popup.isOpen = true;
@@ -399,7 +400,6 @@ class AcePopup {
399400
popup.anchorPos = pos;
400401
popup.anchor = anchor;
401402

402-
dom.$fixPositionBug(el);
403403

404404
return true;
405405
};

src/autocomplete_test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,14 +1719,14 @@ module.exports = {
17191719
value: "completion1",
17201720
docHTML: longDoc
17211721
},
1722-
// {
1723-
// caption: "completion2",
1724-
// value: "completion2"
1725-
// },
1726-
// {
1727-
// caption: "completion3",
1728-
// value: "completion3"
1729-
// }
1722+
{
1723+
caption: "completion2",
1724+
value: "completion2"
1725+
},
1726+
{
1727+
caption: "completion3",
1728+
value: "completion3"
1729+
}
17301730
]);
17311731
}
17321732
}
@@ -1735,8 +1735,7 @@ module.exports = {
17351735

17361736
editor.resize();
17371737
await editor.renderer.once("afterRender");
1738-
1739-
user.type("c");
1738+
editor.completer.showPopup(editor);
17401739

17411740
var popup = editor.completer.popup;
17421741
var popupRect, tooltipRect;
@@ -1758,8 +1757,10 @@ module.exports = {
17581757
editor.container.style.height = "100px";
17591758
editor.container.style.left = "0px";
17601759
editor.container.style.top = "0px";
1761-
popup.container.style.positionHint = editor.completer.tooltipNode.style.positionHint = "fixed"
1762-
1760+
popup.container.style.positionHint = "fixed"
1761+
1762+
1763+
user.type("c");
17631764
await waitForDocTooltip();
17641765
assert.ok(tooltipRect.left > popupRect.right, "Tooltip should appear on the right");
17651766

@@ -1772,17 +1773,16 @@ module.exports = {
17721773

17731774
editor.container.style.left = "400px";
17741775
editor.container.style.top = "0px";
1775-
popup.isTopdown = true;
1776+
popup.container.style.width = (window.innerWidth - 100) + "px";
17761777
user.type("Escape");
17771778
user.type("Enter");
17781779
user.type("c");
17791780

17801781
await waitForDocTooltip();
1781-
assert.ok(tooltipRect.top > popupRect.bottom, "Tooltip should appear below");
1782+
assert.ok(tooltipRect.top >= popupRect.bottom, "Tooltip should appear below");
17821783

17831784
editor.container.style.top = (window.innerHeight - 100) + "px";
17841785
editor.container.style.left = "0px";
1785-
popup.isTopdown = false;
17861786
user.type("Escape");
17871787
user.type("Enter");
17881788
user.type("c");

src/test/mockdom.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,11 @@ function Node(name) {
471471
}
472472
if (!this.style.top && this.style.bottom) {
473473
top = rect.width - bottom - height;
474-
}
474+
}
475+
if (!isFixed) {
476+
top += rect.top;
477+
left += rect.left;
478+
}
475479
}
476480
return {top: top, left: left, width: width, height: height, right: left + width, bottom: top + height};
477481
};

0 commit comments

Comments
 (0)