(cm, rect)
| 3469 | // scrollLeft properties. When these are undefined, the |
| 3470 | // vertical/horizontal position does not need to be adjusted. |
| 3471 | function calculateScrollPos(cm, rect) { |
| 3472 | var display = cm.display, snapMargin = textHeight(cm.display); |
| 3473 | if (rect.top < 0) { rect.top = 0; } |
| 3474 | var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop; |
| 3475 | var screen = displayHeight(cm), result = {}; |
| 3476 | if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; } |
| 3477 | var docBottom = cm.doc.height + paddingVert(display); |
| 3478 | var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin; |
| 3479 | if (rect.top < screentop) { |
| 3480 | result.scrollTop = atTop ? 0 : rect.top; |
| 3481 | } else if (rect.bottom > screentop + screen) { |
| 3482 | var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen); |
| 3483 | if (newTop != screentop) { result.scrollTop = newTop; } |
| 3484 | } |
| 3485 | |
| 3486 | var gutterSpace = cm.options.fixedGutter ? 0 : display.gutters.offsetWidth; |
| 3487 | var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft - gutterSpace; |
| 3488 | var screenw = displayWidth(cm) - display.gutters.offsetWidth; |
| 3489 | var tooWide = rect.right - rect.left > screenw; |
| 3490 | if (tooWide) { rect.right = rect.left + screenw; } |
| 3491 | if (rect.left < 10) |
| 3492 | { result.scrollLeft = 0; } |
| 3493 | else if (rect.left < screenleft) |
| 3494 | { result.scrollLeft = Math.max(0, rect.left + gutterSpace - (tooWide ? 0 : 10)); } |
| 3495 | else if (rect.right > screenw + screenleft - 3) |
| 3496 | { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; } |
| 3497 | return result |
| 3498 | } |
| 3499 | |
| 3500 | // Store a relative adjustment to the scroll position in the current |
| 3501 | // operation (to be applied when the operation finishes). |
no test coverage detected