(cm, update)
| 4165 | // (returning false) when there is nothing to be done and forced is |
| 4166 | // false. |
| 4167 | function updateDisplayIfNeeded(cm, update) { |
| 4168 | var display = cm.display, doc = cm.doc; |
| 4169 | |
| 4170 | if (update.editorIsHidden) { |
| 4171 | resetView(cm); |
| 4172 | return false |
| 4173 | } |
| 4174 | |
| 4175 | // Bail out if the visible area is already rendered and nothing changed. |
| 4176 | if (!update.force && |
| 4177 | update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && |
| 4178 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && |
| 4179 | display.renderedView == display.view && countDirtyView(cm) == 0) |
| 4180 | { return false } |
| 4181 | |
| 4182 | if (maybeUpdateLineNumberWidth(cm)) { |
| 4183 | resetView(cm); |
| 4184 | update.dims = getDimensions(cm); |
| 4185 | } |
| 4186 | |
| 4187 | // Compute a suitable new viewport (from & to) |
| 4188 | var end = doc.first + doc.size; |
| 4189 | var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first); |
| 4190 | var to = Math.min(end, update.visible.to + cm.options.viewportMargin); |
| 4191 | if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); } |
| 4192 | if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); } |
| 4193 | if (sawCollapsedSpans) { |
| 4194 | from = visualLineNo(cm.doc, from); |
| 4195 | to = visualLineEndNo(cm.doc, to); |
| 4196 | } |
| 4197 | |
| 4198 | var different = from != display.viewFrom || to != display.viewTo || |
| 4199 | display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth; |
| 4200 | adjustView(cm, from, to); |
| 4201 | |
| 4202 | display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom)); |
| 4203 | // Position the mover div to align with the current scroll position |
| 4204 | cm.display.mover.style.top = display.viewOffset + "px"; |
| 4205 | |
| 4206 | var toUpdate = countDirtyView(cm); |
| 4207 | if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && |
| 4208 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) |
| 4209 | { return false } |
| 4210 | |
| 4211 | // For big changes, we hide the enclosing element during the |
| 4212 | // update, since that speeds up the operations on most browsers. |
| 4213 | var selSnapshot = selectionSnapshot(cm); |
| 4214 | if (toUpdate > 4) { display.lineDiv.style.display = "none"; } |
| 4215 | patchDisplay(cm, display.updateLineNumbers, update.dims); |
| 4216 | if (toUpdate > 4) { display.lineDiv.style.display = ""; } |
| 4217 | display.renderedView = display.view; |
| 4218 | // There might have been a widget with a focused element that got |
| 4219 | // hidden or updated, if so re-focus it. |
| 4220 | restoreSelection(selSnapshot); |
| 4221 | |
| 4222 | // Prevent selection and cursors from interfering with the scroll |
| 4223 | // width and height. |
| 4224 | removeChildren(display.cursorDiv); |
no test coverage detected