diff --git a/app/editor/extensions/DragHandle.ts b/app/editor/extensions/DragHandle.ts index fa3d48dbce..703530f153 100644 --- a/app/editor/extensions/DragHandle.ts +++ b/app/editor/extensions/DragHandle.ts @@ -197,13 +197,29 @@ export default class DragHandle extends Extension { // :dir(rtl) handling. const isRTL = window.getComputedStyle(next.element).direction === "rtl"; - handle.style.top = + const top = lineMiddle === null - ? `${rect.top - ICON_OFFSET_Y}px` - : `${lineMiddle - ICON_CENTER_Y}px`; - handle.style.left = isRTL - ? `${rect.right + offsetX - HANDLE_SIZE}px` - : `${rect.left - offsetX}px`; + ? rect.top - ICON_OFFSET_Y + : lineMiddle - ICON_CENTER_Y; + const left = isRTL + ? rect.right + offsetX - HANDLE_SIZE + : rect.left - offsetX; + + // Hide the handle past the viewport edge, such as when an inner + // scroll container clips its block, so it does not grow the page. + const { clientWidth, clientHeight } = document.documentElement; + if ( + top + HANDLE_SIZE > clientHeight || + left + HANDLE_SIZE > clientWidth + ) { + handle.classList.remove("visible", "dragging"); + return; + } + + // Position in document coordinates so that the browser scrolls + // the handle with the page, rather than after the scroll event. + handle.style.top = `${top + window.scrollY}px`; + handle.style.left = `${left + window.scrollX}px`; handle.classList.remove("dragging"); handle.classList.add("visible"); }; diff --git a/shared/styles/globals.ts b/shared/styles/globals.ts index 9090ff8a87..81a4f66308 100644 --- a/shared/styles/globals.ts +++ b/shared/styles/globals.ts @@ -184,12 +184,11 @@ export default createGlobalStyle` appearance: none; border: 0; padding: 0; - position: fixed; + position: absolute; width: 24px; height: 24px; cursor: grab; - opacity: 0; - pointer-events: none; + display: none; transition: background-color 150ms ease-in-out; background-color: ${s("textTertiary")}; mask-image: url("${dragHandleIcon}"); @@ -206,8 +205,7 @@ export default createGlobalStyle` } &.visible { - opacity: 1; - pointer-events: auto; + display: block; } &.visible.dragging {