]> git.lyx.org Git - features.git/commitdiff
Make sure that rows are repainted when they get (un)selected
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 29 Nov 2017 10:16:09 +0000 (11:16 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 15 Feb 2018 11:29:25 +0000 (12:29 +0100)
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)

src/Row.cpp
src/Row.h
src/TextMetrics.cpp

index ad492c1a7a53fcd2554b436ffadc5109e82011d1..3fb87bd7e1f3b80504742a85654fa361aca2c4b0 100644 (file)
@@ -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);
 }
 
 
index a1fedd7e5da97d043f8e55936aa8e942903af27e..49513d32b970b63124ce6a3c5290283ab145b317 100644 (file)
--- 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<class T1, class T2>
+       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<class T1, class T2>
+       void change(T1 & var, T2 const val) const {
+               if (var != val)
+                       changed(true);
+               var = val;
+       }
        ///
        bool changed() const { return changed_; }
        ///
index 42637d78993d3065e35a48a1c88df98a908aff28..e7bd6190e28759405821df6cda72e4d245ae5cfa 100644 (file)
@@ -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?