Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

fix(editor): keep the layout picker inside the viewport (#425)

Johan Høgåsen-Hallesby1c54b5fa70ea
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index c0d912eb..fc79f952 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -1755,17 +1755,15 @@ export class Editor {
}
pick.appendChild(grid)
}
+ // Open beside the anchor, clamped on-screen. The bottom-of-sidebar button
+ // used to open the picker upward from itself, which pushed a picker with
+ // a handful of custom layouts above the viewport (measured: top = -7px at
+ // a 600px-tall window). The height is read after appending so the clamp
+ // uses the real box; the stylesheet caps it to the viewport and scrolls.
const r = anchor.getBoundingClientRect()
- if (anchor.classList.contains('ed-add-slide')) {
- // bottom-of-sidebar button: open upward from it
- pick.style.left = `${Math.max(8, r.left)}px`
- pick.style.bottom = `${window.innerHeight - r.top + 8}px`
- } else {
- // insert-gap or panel button: open beside the anchor, clamped on-screen
- pick.style.left = `${Math.max(8, Math.min(r.right + 10, window.innerWidth - 440))}px`
- pick.style.top = `${Math.max(8, Math.min(r.top - 40, window.innerHeight - 460))}px`
- }
+ pick.style.left = `${Math.max(8, Math.min(r.right + 10, window.innerWidth - 440))}px`
document.body.appendChild(pick)
+ pick.style.top = `${Math.max(8, Math.min(r.top - 40, window.innerHeight - pick.offsetHeight - 8))}px`
const close = (ev: PointerEvent) => {
if (!pick.contains(ev.target as Node)) {
pick.remove()
diff --git a/slides/src/styles.css b/slides/src/styles.css
index c7d85005..b77280e6 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -1343,7 +1343,7 @@ a.ed-btn { text-decoration: none; } /* the update block's "What's new" link is
box-shadow: 0 12px 32px rgb(15 23 36 / 0.18);
padding: 12px 14px;
max-width: 420px;
- max-height: 70vh;
+ max-height: calc(100vh - 16px);
overflow-y: auto;
}
.ed-layoutpick-title {