(cm, update)
| 5902 | // (returning false) when there is nothing to be done and forced is |
| 5903 | // false. |
| 5904 | function updateDisplayIfNeeded(cm, update) { |
| 5905 | var display = cm.display, |
| 5906 | doc = cm.doc |
| 5907 | |
| 5908 | if (update.editorIsHidden) { |
| 5909 | resetView(cm) |
| 5910 | return false |
| 5911 | } |
| 5912 | |
| 5913 | // Bail out if the visible area is already rendered and nothing changed. |
| 5914 | if ( |
| 5915 | !update.force && |
| 5916 | update.visible.from >= display.viewFrom && |
| 5917 | update.visible.to <= display.viewTo && |
| 5918 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && |
| 5919 | display.renderedView == display.view && |
| 5920 | countDirtyView(cm) == 0 |
| 5921 | ) { |
| 5922 | return false |
| 5923 | } |
| 5924 | |
| 5925 | if (maybeUpdateLineNumberWidth(cm)) { |
| 5926 | resetView(cm) |
| 5927 | update.dims = getDimensions(cm) |
| 5928 | } |
| 5929 | |
| 5930 | // Compute a suitable new viewport (from & to) |
| 5931 | var end = doc.first + doc.size |
| 5932 | var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first) |
| 5933 | var to = Math.min(end, update.visible.to + cm.options.viewportMargin) |
| 5934 | if (display.viewFrom < from && from - display.viewFrom < 20) { |
| 5935 | from = Math.max(doc.first, display.viewFrom) |
| 5936 | } |
| 5937 | if (display.viewTo > to && display.viewTo - to < 20) { |
| 5938 | to = Math.min(end, display.viewTo) |
| 5939 | } |
| 5940 | if (sawCollapsedSpans) { |
| 5941 | from = visualLineNo(cm.doc, from) |
| 5942 | to = visualLineEndNo(cm.doc, to) |
| 5943 | } |
| 5944 | |
| 5945 | var different = from != display.viewFrom || to != display.viewTo || display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth |
| 5946 | adjustView(cm, from, to) |
| 5947 | |
| 5948 | display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom)) |
| 5949 | // Position the mover div to align with the current scroll position |
| 5950 | cm.display.mover.style.top = display.viewOffset + "px" |
| 5951 | |
| 5952 | var toUpdate = countDirtyView(cm) |
| 5953 | if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) { |
| 5954 | return false |
| 5955 | } |
| 5956 | |
| 5957 | // For big changes, we hide the enclosing element during the |
| 5958 | // update, since that speeds up the operations on most browsers. |
| 5959 | var selSnapshot = selectionSnapshot(cm) |
| 5960 | if (toUpdate > 4) { |
| 5961 | display.lineDiv.style.display = "none" |
no test coverage detected