(cm, update)
| 4072 | // (returning false) when there is nothing to be done and forced is |
| 4073 | // false. |
| 4074 | function updateDisplayIfNeeded(cm, update) { |
| 4075 | var display = cm.display, doc = cm.doc; |
| 4076 | |
| 4077 | if (update.editorIsHidden) { |
| 4078 | resetView(cm); |
| 4079 | return false |
| 4080 | } |
| 4081 | |
| 4082 | // Bail out if the visible area is already rendered and nothing changed. |
| 4083 | if (!update.force && |
| 4084 | update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && |
| 4085 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && |
| 4086 | display.renderedView == display.view && countDirtyView(cm) == 0) |
| 4087 | { return false } |
| 4088 | |
| 4089 | if (maybeUpdateLineNumberWidth(cm)) { |
| 4090 | resetView(cm); |
| 4091 | update.dims = getDimensions(cm); |
| 4092 | } |
| 4093 | |
| 4094 | // Compute a suitable new viewport (from & to) |
| 4095 | var end = doc.first + doc.size; |
| 4096 | var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first); |
| 4097 | var to = Math.min(end, update.visible.to + cm.options.viewportMargin); |
| 4098 | if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); } |
| 4099 | if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); } |
| 4100 | if (sawCollapsedSpans) { |
| 4101 | from = visualLineNo(cm.doc, from); |
| 4102 | to = visualLineEndNo(cm.doc, to); |
| 4103 | } |
| 4104 | |
| 4105 | var different = from != display.viewFrom || to != display.viewTo || |
| 4106 | display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth; |
| 4107 | adjustView(cm, from, to); |
| 4108 | |
| 4109 | display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom)); |
| 4110 | // Position the mover div to align with the current scroll position |
| 4111 | cm.display.mover.style.top = display.viewOffset + "px"; |
| 4112 | |
| 4113 | var toUpdate = countDirtyView(cm); |
| 4114 | if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && |
| 4115 | (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) |
| 4116 | { return false } |
| 4117 | |
| 4118 | // For big changes, we hide the enclosing element during the |
| 4119 | // update, since that speeds up the operations on most browsers. |
| 4120 | var selSnapshot = selectionSnapshot(cm); |
| 4121 | if (toUpdate > 4) { display.lineDiv.style.display = "none"; } |
| 4122 | patchDisplay(cm, display.updateLineNumbers, update.dims); |
| 4123 | if (toUpdate > 4) { display.lineDiv.style.display = ""; } |
| 4124 | display.renderedView = display.view; |
| 4125 | // There might have been a widget with a focused element that got |
| 4126 | // hidden or updated, if so re-focus it. |
| 4127 | restoreSelection(selSnapshot); |
| 4128 | |
| 4129 | // Prevent selection and cursors from interfering with the scroll |
| 4130 | // width and height. |
| 4131 | removeChildren(display.cursorDiv); |
no test coverage detected