(cm, pos, end, margin)
| 3425 | // it actually became visible (as line heights are accurately |
| 3426 | // measured, the position of something may 'drift' during drawing). |
| 3427 | function scrollPosIntoView(cm, pos, end, margin) { |
| 3428 | if (margin == null) { margin = 0; } |
| 3429 | var rect; |
| 3430 | if (!cm.options.lineWrapping && pos == end) { |
| 3431 | // Set pos and end to the cursor positions around the character pos sticks to |
| 3432 | // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch |
| 3433 | // If pos == Pos(_, 0, "before"), pos and end are unchanged |
| 3434 | pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos; |
| 3435 | end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos; |
| 3436 | } |
| 3437 | for (var limit = 0; limit < 5; limit++) { |
| 3438 | var changed = false; |
| 3439 | var coords = cursorCoords(cm, pos); |
| 3440 | var endCoords = !end || end == pos ? coords : cursorCoords(cm, end); |
| 3441 | rect = {left: Math.min(coords.left, endCoords.left), |
| 3442 | top: Math.min(coords.top, endCoords.top) - margin, |
| 3443 | right: Math.max(coords.left, endCoords.left), |
| 3444 | bottom: Math.max(coords.bottom, endCoords.bottom) + margin}; |
| 3445 | var scrollPos = calculateScrollPos(cm, rect); |
| 3446 | var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft; |
| 3447 | if (scrollPos.scrollTop != null) { |
| 3448 | updateScrollTop(cm, scrollPos.scrollTop); |
| 3449 | if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; } |
| 3450 | } |
| 3451 | if (scrollPos.scrollLeft != null) { |
| 3452 | setScrollLeft(cm, scrollPos.scrollLeft); |
| 3453 | if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; } |
| 3454 | } |
| 3455 | if (!changed) { break } |
| 3456 | } |
| 3457 | return rect |
| 3458 | } |
| 3459 | |
| 3460 | // Scroll a given set of coordinates into view (immediately). |
| 3461 | function scrollIntoView(cm, rect) { |
no test coverage detected