(cm, pos, end, margin)
| 4875 | // it actually became visible (as line heights are accurately |
| 4876 | // measured, the position of something may 'drift' during drawing). |
| 4877 | function scrollPosIntoView(cm, pos, end, margin) { |
| 4878 | if (margin == null) { |
| 4879 | margin = 0 |
| 4880 | } |
| 4881 | var rect |
| 4882 | if (!cm.options.lineWrapping && pos == end) { |
| 4883 | // Set pos and end to the cursor positions around the character pos sticks to |
| 4884 | // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch |
| 4885 | // If pos == Pos(_, 0, "before"), pos and end are unchanged |
| 4886 | pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos |
| 4887 | end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos |
| 4888 | } |
| 4889 | for (var limit = 0; limit < 5; limit++) { |
| 4890 | var changed = false |
| 4891 | var coords = cursorCoords(cm, pos) |
| 4892 | var endCoords = !end || end == pos ? coords : cursorCoords(cm, end) |
| 4893 | rect = { left: Math.min(coords.left, endCoords.left), top: Math.min(coords.top, endCoords.top) - margin, right: Math.max(coords.left, endCoords.left), bottom: Math.max(coords.bottom, endCoords.bottom) + margin } |
| 4894 | var scrollPos = calculateScrollPos(cm, rect) |
| 4895 | var startTop = cm.doc.scrollTop, |
| 4896 | startLeft = cm.doc.scrollLeft |
| 4897 | if (scrollPos.scrollTop != null) { |
| 4898 | updateScrollTop(cm, scrollPos.scrollTop) |
| 4899 | if (Math.abs(cm.doc.scrollTop - startTop) > 1) { |
| 4900 | changed = true |
| 4901 | } |
| 4902 | } |
| 4903 | if (scrollPos.scrollLeft != null) { |
| 4904 | setScrollLeft(cm, scrollPos.scrollLeft) |
| 4905 | if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { |
| 4906 | changed = true |
| 4907 | } |
| 4908 | } |
| 4909 | if (!changed) { |
| 4910 | break |
| 4911 | } |
| 4912 | } |
| 4913 | return rect |
| 4914 | } |
| 4915 | |
| 4916 | // Scroll a given set of coordinates into view (immediately). |
| 4917 | function scrollIntoView(cm, rect) { |
no test coverage detected