(cm, pos, end, margin)
| 4624 | // it actually became visible (as line heights are accurately |
| 4625 | // measured, the position of something may 'drift' during drawing). |
| 4626 | function scrollPosIntoView(cm, pos, end, margin) { |
| 4627 | if (margin == null) margin = 0; |
| 4628 | for (var limit = 0; limit < 5; limit++) { |
| 4629 | var changed = false, coords = cursorCoords(cm, pos); |
| 4630 | var endCoords = !end || end == pos ? coords : cursorCoords(cm, end); |
| 4631 | var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left), |
| 4632 | Math.min(coords.top, endCoords.top) - margin, |
| 4633 | Math.max(coords.left, endCoords.left), |
| 4634 | Math.max(coords.bottom, endCoords.bottom) + margin); |
| 4635 | var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft; |
| 4636 | if (scrollPos.scrollTop != null) { |
| 4637 | setScrollTop(cm, scrollPos.scrollTop); |
| 4638 | if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true; |
| 4639 | } |
| 4640 | if (scrollPos.scrollLeft != null) { |
| 4641 | setScrollLeft(cm, scrollPos.scrollLeft); |
| 4642 | if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true; |
| 4643 | } |
| 4644 | if (!changed) break; |
| 4645 | } |
| 4646 | return coords; |
| 4647 | } |
| 4648 | |
| 4649 | // Scroll a given set of coordinates into view (immediately). |
| 4650 | function scrollIntoView(cm, x1, y1, x2, y2) { |
no test coverage detected