(cm, pos, end, margin)
| 4422 | // it actually became visible (as line heights are accurately |
| 4423 | // measured, the position of something may 'drift' during drawing). |
| 4424 | function scrollPosIntoView(cm, pos, end, margin) { |
| 4425 | if (margin == null) margin = 0; |
| 4426 | for (var limit = 0; limit < 5; limit++) { |
| 4427 | var changed = false, coords = cursorCoords(cm, pos); |
| 4428 | var endCoords = !end || end == pos ? coords : cursorCoords(cm, end); |
| 4429 | var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left), |
| 4430 | Math.min(coords.top, endCoords.top) - margin, |
| 4431 | Math.max(coords.left, endCoords.left), |
| 4432 | Math.max(coords.bottom, endCoords.bottom) + margin); |
| 4433 | var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft; |
| 4434 | if (scrollPos.scrollTop != null) { |
| 4435 | setScrollTop(cm, scrollPos.scrollTop); |
| 4436 | if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true; |
| 4437 | } |
| 4438 | if (scrollPos.scrollLeft != null) { |
| 4439 | setScrollLeft(cm, scrollPos.scrollLeft); |
| 4440 | if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true; |
| 4441 | } |
| 4442 | if (!changed) break; |
| 4443 | } |
| 4444 | return coords; |
| 4445 | } |
| 4446 | |
| 4447 | // Scroll a given set of coordinates into view (immediately). |
| 4448 | function scrollIntoView(cm, x1, y1, x2, y2) { |
no test coverage detected