(cm, rect)
| 13 | // If an editor sits on the top or bottom of the window, partially |
| 14 | // scrolled out of view, this ensures that the cursor is visible. |
| 15 | export function maybeScrollWindow(cm, rect) { |
| 16 | if (signalDOMEvent(cm, "scrollCursorIntoView")) return |
| 17 | |
| 18 | let display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null |
| 19 | if (rect.top + box.top < 0) doScroll = true |
| 20 | else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false |
| 21 | if (doScroll != null && !phantom) { |
| 22 | let scrollNode = elt("div", "\u200b", null, `position: absolute; |
| 23 | top: ${rect.top - display.viewOffset - paddingTop(cm.display)}px; |
| 24 | height: ${rect.bottom - rect.top + scrollGap(cm) + display.barHeight}px; |
| 25 | left: ${rect.left}px; width: ${Math.max(2, rect.right - rect.left)}px;`) |
| 26 | cm.display.lineSpace.appendChild(scrollNode) |
| 27 | scrollNode.scrollIntoView(doScroll) |
| 28 | cm.display.lineSpace.removeChild(scrollNode) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // Scroll a given position into view (immediately), verifying that |
| 33 | // it actually became visible (as line heights are accurately |
no test coverage detected