(cm, update)
| 4104 | // (returning false) when there is nothing to be done and forced is |
| 4105 | // false. |
| 4106 | function updateDisplayIfNeeded(cm, update) { |
| 4107 | var display = cm.display, doc = cm.doc; |
| 4108 | |
| 4109 | if (update.editorIsHidden) { |
| 4110 | resetView(cm); |
| 4111 | return false |
| 4112 | } |
| 4113 | |
| 4114 | // Bail out if the visible area is already rendered and nothing changed. |
| 4115 | if (!update.force && |
| 4116 | update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && |
| 4117 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && |
| 4118 | display.renderedView == display.view && countDirtyView(cm) == 0) |
| 4119 | { return false } |
| 4120 | |
| 4121 | if (maybeUpdateLineNumberWidth(cm)) { |
| 4122 | resetView(cm); |
| 4123 | update.dims = getDimensions(cm); |
| 4124 | } |
| 4125 | |
| 4126 | // Compute a suitable new viewport (from & to) |
| 4127 | var end = doc.first + doc.size; |
| 4128 | var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first); |
| 4129 | var to = Math.min(end, update.visible.to + cm.options.viewportMargin); |
| 4130 | if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); } |
| 4131 | if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); } |
| 4132 | if (sawCollapsedSpans) { |
| 4133 | from = visualLineNo(cm.doc, from); |
| 4134 | to = visualLineEndNo(cm.doc, to); |
| 4135 | } |
| 4136 | |
| 4137 | var different = from != display.viewFrom || to != display.viewTo || |
| 4138 | display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth; |
| 4139 | adjustView(cm, from, to); |
| 4140 | |
| 4141 | display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom)); |
| 4142 | // Position the mover div to align with the current scroll position |
| 4143 | cm.display.mover.style.top = display.viewOffset + "px"; |
| 4144 | |
| 4145 | var toUpdate = countDirtyView(cm); |
| 4146 | if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && |
| 4147 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) |
| 4148 | { return false } |
| 4149 | |
| 4150 | // For big changes, we hide the enclosing element during the |
| 4151 | // update, since that speeds up the operations on most browsers. |
| 4152 | var selSnapshot = selectionSnapshot(cm); |
| 4153 | if (toUpdate > 4) { display.lineDiv.style.display = "none"; } |
| 4154 | patchDisplay(cm, display.updateLineNumbers, update.dims); |
| 4155 | if (toUpdate > 4) { display.lineDiv.style.display = ""; } |
| 4156 | display.renderedView = display.view; |
| 4157 | // There might have been a widget with a focused element that got |
| 4158 | // hidden or updated, if so re-focus it. |
| 4159 | restoreSelection(selSnapshot); |
| 4160 | |
| 4161 | // Prevent selection and cursors from interfering with the scroll |
| 4162 | // width and height. |
| 4163 | removeChildren(display.cursorDiv); |
no test coverage detected