Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assets/css/js_interop.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ we hide/show certain elements. This way we don't have to engage the
server in solely client-side operations.
*/

/* Prevent scroll jump when cell body is focused (e.g., clicking on output) */
[data-el-cell-body] {
scroll-margin-top: 50px;
scroll-margin-bottom: 50px;
}

/* Hooks */

[phx-hook="Dropzone"][data-js-dragging] {
Expand Down
20 changes: 20 additions & 0 deletions assets/js/hooks/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ const Cell = {
this.el.setAttribute("data-js-hover", "");
});

// Prevent scroll jump when clicking on cell output by handling mousedown
// on the cell body. This ensures clicking on output doesn't trigger
// unwanted scroll behavior when the cell body receives focus.
const cellBody = this.el.querySelector(`[data-el-cell-body]`);
if (cellBody) {
cellBody.addEventListener("mousedown", (event) => {
// If clicking on output (not an editor), prevent default focus scroll
if (!event.target.closest(`[data-el-editor-container]`)) {
// Save scroll position before focus changes
const scrollX = window.scrollX;
const scrollY = window.scrollY;

// After focus is applied, restore scroll position
requestAnimationFrame(() => {
window.scrollTo(scrollX, scrollY);
});
}
});
}

this.el.addEventListener("mouseleave", (event) => {
this.el.removeAttribute("data-js-hover");
});
Expand Down