- // Force the recomputation of inset positions
- bool const drawing = pi.pain.isDrawingEnabled();
- pi.pain.setDrawingEnabled(false);
- // No need to care about vertical position.
- RowPainter rp(pi, buffer().text(), d->cursor_.bottom().pit(), row, 0, 0);
- rp.paintText();
- pi.pain.setDrawingEnabled(drawing);
+ // If insets referred to by cursor are not all in the cache, the positions
+ // need to be recomputed.
+ if (!d->cursor_.inCoordCache()) {
+ /** FIXME: the code below adds an extraneous computation of
+ * inset positions, and can therefore be bad for performance
+ * (think for example about a very large tabular inset.
+ * Redawing the row where it is means redrawing the whole
+ * screen).
+ *
+ * The bug that this fixes is the following: assume that there
+ * is a very large math inset. Upon entering the inset, when
+ * pressing `End', the row is not scrolled and the cursor is
+ * not visible. The extra row computation makes sure that the
+ * inset positions are correctly computed and set in the
+ * cache. This would not happen if we did not have two-stage
+ * drawing.
+ *
+ * A proper fix would be to always have proper inset positions
+ * at this point.
+ */
+ // Force the recomputation of inset positions
+ bool const drawing = pi.pain.isDrawingEnabled();
+ pi.pain.setDrawingEnabled(false);
+ // No need to care about vertical position.
+ RowPainter rp(pi, buffer().text(), row, -d->horiz_scroll_offset_, 0);
+ rp.paintText();
+ pi.pain.setDrawingEnabled(drawing);
+ }