diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 73cf4520b9..2101ede702 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -237,7 +237,7 @@ struct BufferView::Private last_inset_(0), clickable_inset_(false), mouse_position_cache_(), bookmark_edit_position_(-1), gui_(0), - horiz_scroll_offset_(0), repaint_caret_row_(false) + horiz_scroll_offset_(0) { xsel_cache_.set = false; } @@ -316,12 +316,6 @@ struct BufferView::Private /// a slice pointing to the start of the row where cursor was /// at previous draw event CursorSlice last_row_slice_; - - /// a slice pointing to where the cursor has been drawn after the current - /// draw() call. - CursorSlice caret_slice_; - /// indicates whether the caret slice needs to be repainted in this draw() run. - bool repaint_caret_row_; }; @@ -3063,29 +3057,6 @@ void BufferView::setCurrentRowSlice(CursorSlice const & rowSlice) } -namespace { - -bool sliceInRow(CursorSlice const & cs, Text const * text, Row const & row) -{ - /* The normal case is the last line. The previous line takes care - * of empty rows (e.g. empty paragraphs). Cursor boundary issues - * are taken care of when setting caret_slice_ in - * BufferView::draw. - */ - return !cs.empty() && cs.text() == text && cs.pit() == row.pit() - && ((row.pos() == row.endpos() && row.pos() == cs.pos()) - || (row.pos() <= cs.pos() && cs.pos() < row.endpos())); -} - -} - - -bool BufferView::needRepaint(Text const * text, Row const & row) const -{ - return d->repaint_caret_row_ && sliceInRow(d->caret_slice_, text, row); -} - - void BufferView::checkCursorScrollOffset() { CursorSlice rowSlice = d->cursor_.bottom(); @@ -3157,16 +3128,6 @@ void BufferView::draw(frontend::Painter & pain, bool paint_caret) int const y = tm.first().second->position(); PainterInfo pi(this, pain); - /** A repaint of the previous caret row is needed if there is - * caret painted on screen and either - * 1/ a new caret has to be painted at a place different from - * the existing one; - * 2/ there is no need for a caret anymore. - */ - d->repaint_caret_row_ = !d->caret_slice_.empty() && - ((paint_caret && d->cursor_.top() != d->caret_slice_) - || ! paint_caret); - // Check whether the row where the cursor lives needs to be scrolled. // Update the drawing strategy if needed. checkCursorScrollOffset(); @@ -3182,7 +3143,7 @@ void BufferView::draw(frontend::Painter & pain, bool paint_caret) if (pain.isNull()) { pi.full_repaint = true; tm.draw(pi, 0, y); - } else if (d->repaint_caret_row_) { + } else { pi.full_repaint = false; tm.draw(pi, 0, y); } @@ -3256,15 +3217,15 @@ void BufferView::draw(frontend::Painter & pain, bool paint_caret) d->update_flags_ = Update::None; } - // Remember what has just been done for the next draw() step + // If a caret has to be painted, mark its text row as dirty to + //make sure that it will be repainted on next redraw. + /* FIXME: investigate whether this can be avoided when the cursor did not + * move at all + */ if (paint_caret) { - d->caret_slice_ = d->cursor_.top(); - if (d->caret_slice_.pos() > 0 - && (d->cursor_.boundary() - || d->caret_slice_.pos() == d->caret_slice_.lastpos())) - --d->caret_slice_.pos(); - } else - d->caret_slice_ = CursorSlice(); + Row const & caret_row = d->cursor_.textRow(); + caret_row.changed(true); + } } diff --git a/src/BufferView.h b/src/BufferView.h index 3cbf22a8ba..733e66f926 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -133,9 +133,6 @@ public: /// Only to be called with good y coordinates (after a bv::metrics) bool needsFitCursor() const; - /// returns true if this row needs to be repainted (to erase caret) - bool needRepaint(Text const * text, Row const & row) const; - // Returns the amount of horizontal scrolling applied to the // top-level row where the cursor lies int horizScrollOffset() const; diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 5d4b88d604..e5345dd040 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1891,8 +1891,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const // has row changed since last paint? bool row_has_changed = row.changed() - || bv_->hadHorizScrollOffset(text_, pit, row.pos()) - || bv_->needRepaint(text_, row); + || bv_->hadHorizScrollOffset(text_, pit, row.pos()); // Take this opportunity to spellcheck the row contents. if (row_has_changed && pi.do_spellcheck && lyxrc.spellcheck_continuously) {