#include "Paragraph.h"
#include "ParagraphParameters.h"
#include "ParIterator.h"
+#include "RowPainter.h"
#include "Session.h"
#include "Text.h"
#include "TextClass.h"
cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos();
}
+ cur.setCurrentFont();
dr.screenUpdate(Update::Force);
break;
// FIXME (Abdel 23/09/2007): this is a bit messy because of the
// elimination of Inset::dim_ cache. This coordOffset() method needs
// to be rewritten in light of the new design.
- Dimension const & dim = parMetrics(dit[i - 1].text(),
- dit[i - 1].pit()).insetDimension(&sl.inset());
+ Dimension const & dim = coordCache().getInsets().dim(&sl.inset());
lastw = dim.wid;
} else {
Dimension const dim = sl.inset().dimension(*this);
}
-void BufferView::checkCursorScrollOffset()
+void BufferView::checkCursorScrollOffset(PainterInfo & pi)
{
CursorSlice rowSlice = d->cursor_.bottom();
TextMetrics const & tm = textMetrics(rowSlice.text());
setCurrentRowSlice(rowSlice);
// Current x position of the cursor in pixels
- int const cur_x = getPos(d->cursor_).x_;
+ int cur_x = getPos(d->cursor_).x_;
+
+ // If cursor offset is left margin and offset is not the leftmost
+ // position of the row, there is a cache problem.
+ if (cur_x == row.left_margin && !row.empty()
+ && d->cursor_.pos() != row.front().left_pos()) {
+ /** 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 should be found and this code should be removed.
+ */
+ // 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,
+ -d->horiz_scroll_offset_, 0);
+ rp.paintText();
+ pi.pain.setDrawingEnabled(drawing);
+
+ // Recompute current Current x position of the cursor in pixels
+ cur_x = getPos(d->cursor_).x_;
+ }
// Horizontal scroll offset of the cursor row in pixels
int offset = d->horiz_scroll_offset_;
- int const MARGIN = 2 * theFontMetrics(d->cursor_.real_current_font).em();
- //lyxerr << "cur_x=" << cur_x << ", offset=" << offset << ", margin=" << MARGIN << endl;
- if (cur_x < offset + MARGIN) {
- // scroll right
- offset = cur_x - MARGIN;
- } else if (cur_x > offset + workWidth() - MARGIN) {
- // scroll left
- offset = cur_x - workWidth() + MARGIN;
+ int const MARGIN = 2 * theFontMetrics(d->cursor_.real_current_font).em()
+ + row.right_margin;
+ if (row.right_x() <= workWidth() - row.right_margin) {
+ // Row is narrower than the work area, no offset needed.
+ offset = 0;
+ } else {
+ if (cur_x - offset < MARGIN) {
+ // cursor would be too far right
+ offset = cur_x - MARGIN;
+ } else if (cur_x - offset > workWidth() - MARGIN) {
+ // cursor would be too far left
+ offset = cur_x - workWidth() + MARGIN;
+ }
+ // Correct the offset to make sure that we do not scroll too much
+ if (offset < 0)
+ offset = 0;
+ if (row.right_x() - offset < workWidth() - row.right_margin)
+ offset = row.right_x() - workWidth() + row.right_margin;
}
- if (offset < row.left_margin || row.width() <= workWidth())
- offset = 0;
+ //lyxerr << "cur_x=" << cur_x << ", offset=" << offset << ", row.wid=" << row.width() << ", margin=" << MARGIN << endl;
if (offset != d->horiz_scroll_offset_)
LYXERR(Debug::PAINTING, "Horiz. scroll offset changed from "
// Check whether the row where the cursor lives needs to be scrolled.
// Update the drawing strategy if needed.
- checkCursorScrollOffset();
+ checkCursorScrollOffset(pi);
switch (d->update_strategy_) {