- if (d->update_flags_ == Update::FitCursor
- || d->update_flags_ == (Update::Decoration | Update::FitCursor)) {
- // tell the frontend to update the screen if needed.
+ /* FIXME We would like to avoid doing this here, since it is very
+ * expensive and is called in updateBuffer already. However, even
+ * inserting a plain character can invalidate the overly fragile
+ * tables of child documents built by updateMacros. Some work is
+ * needed to avoid doing that when not necessary.
+ */
+ buffer_.updateMacros();
+
+ // First check whether the metrics and inset positions should be updated
+ if (flags & Update::Force) {
+ // This will update the CoordCache items and replace Force
+ // with ForceDraw in flags.
+ updateMetrics(flags);
+ }
+
+ // Detect whether we can only repaint a single paragraph (if we
+ // are not already redrawing all).
+ // We handle this before FitCursor because the later will require
+ // correct metrics at cursor position.
+ if (!(flags & Update::ForceDraw)
+ && (flags & Update::SinglePar)
+ && !singleParUpdate())
+ updateMetrics(flags);
+
+ // Then make sure that the screen contains the cursor if needed
+ if (flags & Update::FitCursor) {