Skip to content

Commit 0bcf66e

Browse files
committed
👌 Improve horizontal positioning
1 parent 78faba9 commit 0bcf66e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/sphinx_peek/assets/sphinx_peek.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,16 @@ function setPreviewPosition(preview, anchor, config) {
144144
let pos_screen_top = position_anchor.top + config.offset.top;
145145
let width = config.width;
146146
let height = config.height;
147+
let marginX = 10;
147148

148-
// ensure width is not bigger than window width
149-
if (width > window.innerWidth) {
150-
width = window.innerWidth;
149+
// ensure width is not bigger than window width + margin
150+
let maxWidth = window.innerWidth - marginX * 2;
151+
if (width > maxWidth) {
152+
width = maxWidth;
151153
}
152-
// anchor left of link if not enough space on right
153-
if (pos_screen_left + width + 50 > window.innerWidth) {
154-
pos_left = window.innerWidth - width - 50;
155-
}
156-
if (pos_left < 0) {
157-
pos_left = 50;
154+
// ensure whole width is visible on screen
155+
if (pos_screen_left + width + marginX > window.innerWidth) {
156+
pos_left = window.innerWidth - width - marginX;
158157
}
159158
// ensure height is not bigger than window height
160159
if (height > window.innerHeight) {

0 commit comments

Comments
 (0)