Skip to content

Commit 985bfa6

Browse files
committed
👌 Improve vertical positioning
1 parent 0bcf66e commit 985bfa6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/sphinx_peek/assets/sphinx_peek.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,20 @@ function setPreviewPosition(preview, anchor, config) {
159159
if (height > window.innerHeight) {
160160
height = window.innerHeight;
161161
}
162-
// anchor above link if not enough space below,
163-
// and if there is enough space above
164-
if (
165-
pos_screen_top + height > window.innerHeight &&
166-
pos_screen_top - height - 10 > 0
167-
) {
168-
pos_screen_top = position_anchor.top - height - 10;
162+
163+
// is the whole height not visible below the anchor
164+
if (pos_screen_top + height > window.innerHeight) {
165+
if (window.innerHeight - position_anchor.top > position_anchor.top) {
166+
// more space below the anchor, so just it overflow the screen
167+
} else {
168+
// more space above the anchor, so move it there
169+
pos_screen_top = position_anchor.top - height - 10;
170+
if (pos_screen_top < 10) {
171+
// shrink height to fit in screen
172+
pos_screen_top = 10;
173+
height = position_anchor.top - 20;
174+
}
175+
}
169176
}
170177
// set preview position and size via css
171178
preview.style.width = width + "px";

0 commit comments

Comments
 (0)