]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
do what the FIXME suggested
[lyx.git] / src / TextMetrics.cpp
index 381e6cb3263a6f0887ee9dd1064b9ec9fb0e5018..ca2670b6e1b2f2c7a9346276ff55d821557d2168 100644 (file)
@@ -423,28 +423,6 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                changed |= (old_dim != dim);
        }
 
-       Cursor const & cur = bv_->cursor();
-       DocIterator sel_beg = cur.selectionBegin();
-       DocIterator sel_end = cur.selectionEnd();
-       bool selection = cur.selection()
-               // This is out text.
-               && cur.text() == text_
-               // if the anchor is outside, this is not our selection 
-               && cur.anchor().text() == text_
-               && pit >= sel_beg.pit() && pit <= sel_end.pit();
-
-       // We care only about visible selection.
-       if (selection) {
-               if (pit != sel_beg.pit()) {
-                       sel_beg.pit() = pit;
-                       sel_beg.pos() = 0;
-               }
-               if (pit != sel_end.pit()) {
-                       sel_end.pit() = pit;
-                       sel_end.pos() = sel_end.lastpos();
-               }
-       }
-
        par.setBeginOfBody();
        pos_type first = 0;
        size_t row_index = 0;
@@ -467,10 +445,6 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                row.setChanged(false);
                row.pos(first);
                row.endpos(end);
-               if (selection)
-                       row.setSelection(sel_beg.pos(), sel_end.pos());
-               else
-                       row.setSelection(-1, -1);
                row.setDimension(dim);
                int const max_row_width = max(dim_.wid, dim.wid);
                computeRowMetrics(pit, row, max_row_width);
@@ -1961,6 +1935,28 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
        int const ww = bv_->workHeight();
        size_t const nrows = pm.rows().size();
 
+       Cursor const & cur = bv_->cursor();
+       DocIterator sel_beg = cur.selectionBegin();
+       DocIterator sel_end = cur.selectionEnd();
+       bool selection = cur.selection()
+               // This is our text.
+               && cur.text() == text_
+               // if the anchor is outside, this is not our selection 
+               && cur.anchor().text() == text_
+               && pit >= sel_beg.pit() && pit <= sel_end.pit();
+
+       // We care only about visible selection.
+       if (selection) {
+               if (pit != sel_beg.pit()) {
+                       sel_beg.pit() = pit;
+                       sel_beg.pos() = 0;
+               }
+               if (pit != sel_end.pit()) {
+                       sel_end.pit() = pit;
+                       sel_end.pos() = sel_end.lastpos();
+               }
+       }
+
        for (size_t i = 0; i != nrows; ++i) {
 
                Row const & row = pm.rows()[i];
@@ -1973,6 +1969,11 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
                pi.pain.setDrawingEnabled(inside && original_drawing_state);
                RowPainter rp(pi, *text_, pit, row, bidi, x, y);
 
+               if (selection)
+                       row.setSelection(sel_beg.pos(), sel_end.pos());
+               else
+                       row.setSelection(-1, -1);
+
                // Row signature; has row changed since last paint?
                row.setCrc(pm.computeRowSignature(row, bparams));
                bool row_has_changed = row.changed();