(cm, x1, y1, x2, y2)
| 4658 | // scrollLeft properties. When these are undefined, the |
| 4659 | // vertical/horizontal position does not need to be adjusted. |
| 4660 | function calculateScrollPos(cm, x1, y1, x2, y2) { |
| 4661 | var display = cm.display, snapMargin = textHeight(cm.display); |
| 4662 | if (y1 < 0) y1 = 0; |
| 4663 | var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop; |
| 4664 | var screen = displayHeight(cm), result = {}; |
| 4665 | if (y2 - y1 > screen) y2 = y1 + screen; |
| 4666 | var docBottom = cm.doc.height + paddingVert(display); |
| 4667 | var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin; |
| 4668 | if (y1 < screentop) { |
| 4669 | result.scrollTop = atTop ? 0 : y1; |
| 4670 | } else if (y2 > screentop + screen) { |
| 4671 | var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen); |
| 4672 | if (newTop != screentop) result.scrollTop = newTop; |
| 4673 | } |
| 4674 | |
| 4675 | var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft; |
| 4676 | var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0); |
| 4677 | var tooWide = x2 - x1 > screenw; |
| 4678 | if (tooWide) x2 = x1 + screenw; |
| 4679 | if (x1 < 10) |
| 4680 | result.scrollLeft = 0; |
| 4681 | else if (x1 < screenleft) |
| 4682 | result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10)); |
| 4683 | else if (x2 > screenw + screenleft - 3) |
| 4684 | result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw; |
| 4685 | return result; |
| 4686 | } |
| 4687 | |
| 4688 | // Store a relative adjustment to the scroll position in the current |
| 4689 | // operation (to be applied when the operation finishes). |
no test coverage detected