Skip to content

Commit

Permalink
👌 Improve vertical positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jan 24, 2024
1 parent 0bcf66e commit 985bfa6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/sphinx_peek/assets/sphinx_peek.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,20 @@ function setPreviewPosition(preview, anchor, config) {
if (height > window.innerHeight) {
height = window.innerHeight;
}
// anchor above link if not enough space below,
// and if there is enough space above
if (
pos_screen_top + height > window.innerHeight &&
pos_screen_top - height - 10 > 0
) {
pos_screen_top = position_anchor.top - height - 10;

// is the whole height not visible below the anchor
if (pos_screen_top + height > window.innerHeight) {
if (window.innerHeight - position_anchor.top > position_anchor.top) {
// more space below the anchor, so just it overflow the screen
} else {
// more space above the anchor, so move it there
pos_screen_top = position_anchor.top - height - 10;
if (pos_screen_top < 10) {
// shrink height to fit in screen
pos_screen_top = 10;
height = position_anchor.top - 20;
}
}
}
// set preview position and size via css
preview.style.width = width + "px";
Expand Down

0 comments on commit 985bfa6

Please sign in to comment.