From: Jean-Marc Lasgouttes Date: Wed, 29 Nov 2017 10:16:09 +0000 (+0100) Subject: Make sure that rows are repainted when they get (un)selected X-Git-Tag: 2.3.1~133^2~88^2~3 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8af3077753381238e1fb3e21d65017b94778a47c;p=features.git Make sure that rows are repainted when they get (un)selected The bug is the following: when selecting several paragraphs quickly enough, some rows do not get selected.This is a consequence of the removal of row crc, which lead to not taking into account the selection status of the row in the decision to repaint. The solution chosen here is to add a Row::change() helper function to modify row members. This will set the Row changed status whenever the value of the member changes. (cherry picked from commit ae60749f89fb4ee0fca05ac75979d434f6b0401d) --- diff --git a/src/Row.cpp b/src/Row.cpp index ad492c1a7a..3fb87bd7e1 100644 --- a/src/Row.cpp +++ b/src/Row.cpp @@ -203,8 +203,8 @@ void Row::setSelectionAndMargins(DocIterator const & beg, setSelection(beg.pos(), end.pos()); if (selection()) { - end_margin_sel = isMarginSelected(false, beg, end); - begin_margin_sel = isMarginSelected(true, beg, end); + change(end_margin_sel, isMarginSelected(false, beg, end)); + change(begin_margin_sel, isMarginSelected(true, beg, end)); } } @@ -212,18 +212,18 @@ void Row::setSelectionAndMargins(DocIterator const & beg, void Row::setSelection(pos_type beg, pos_type end) const { if (pos_ >= beg && pos_ <= end) - sel_beg = pos_; + change(sel_beg, pos_); else if (beg > pos_ && beg <= end_) - sel_beg = beg; + change(sel_beg, beg); else - sel_beg = -1; + change(sel_beg, -1); if (end_ >= beg && end_ <= end) - sel_end = end_; + change(sel_end,end_); else if (end < end_ && end >= pos_) - sel_end = end; + change(sel_end, end); else - sel_end = -1; + change(sel_end, -1); } diff --git a/src/Row.h b/src/Row.h index a1fedd7e5d..49513d32b9 100644 --- a/src/Row.h +++ b/src/Row.h @@ -136,6 +136,29 @@ public: /// Row(); + /** + * Helper function: set variable \c var to value \c val, and mark + * row as changed is the values were different. This is intended + * for use when changing members of the row object. + */ + template + void change(T1 & var, T2 const val) { + if (var != val) + changed(true); + var = val; + } + /** + * Helper function: set variable \c var to value \c val, and mark + * row as changed is the values were different. This is intended + * for use when changing members of the row object. + * This is the const version, useful for mutable members. + */ + template + void change(T1 & var, T2 const val) const { + if (var != val) + changed(true); + var = val; + } /// bool changed() const { return changed_; } /// diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 42637d7899..e7bd6190e2 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1884,9 +1884,9 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const // whether this row is the first or last and update the margins. if (row.selection()) { if (row.sel_beg == 0) - row.begin_margin_sel = sel_beg.pit() < pit; + row.change(row.begin_margin_sel, sel_beg.pit() < pit); if (row.sel_end == sel_end_par.lastpos()) - row.end_margin_sel = sel_end.pit() > pit; + row.change(row.end_margin_sel, sel_end.pit() > pit); } // has row changed since last paint?