]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
make \lyxadded and \lyxdeleted robust (#8435)
[lyx.git] / src / TextMetrics.cpp
index 1000affa05421b30e201e9a6de69e8690ab0d2d5..938223050961fbe55778f9d7719849ae62ba137f 100644 (file)
@@ -375,19 +375,28 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        main_text_ = (text_ == &buffer.text());
        bool changed = false;
 
+       // Check whether there are InsetBibItems that need fixing
        // FIXME: This check ought to be done somewhere else. It is the reason
-       // why text_ is not     const. But then, where else to do it?
+       // why text_ is not const. But then, where else to do it?
        // Well, how can you end up with either (a) a biblio environment that
        // has no InsetBibitem or (b) a biblio environment with more than one
        // InsetBibitem? I think the answer is: when paragraphs are merged;
        // when layout is set; when material is pasted.
-       int const moveCursor = par.checkBiblio(buffer);
-       if (moveCursor > 0)
-               const_cast<Cursor &>(bv_->cursor()).posForward();
-       else if (moveCursor < 0) {
-               Cursor & cursor = const_cast<Cursor &>(bv_->cursor());
-               if (cursor.pos() >= -moveCursor)
-                       cursor.posBackward();
+       if (par.brokenBiblio()) {
+               Cursor & cur = const_cast<Cursor &>(bv_->cursor());
+               // In some cases, we do not know how to record undo
+               if (&cur.inset() == &text_->inset())
+                       cur.recordUndo(ATOMIC_UNDO, pit, pit);
+
+               int const moveCursor = par.fixBiblio(buffer);
+
+               // Is it necessary to update the cursor?
+               if (&cur.inset() == &text_->inset() && cur.pit() == pit) {
+                       if (moveCursor > 0)
+                               cur.posForward();
+                       else if (moveCursor < 0 && cur.pos() >= -moveCursor)
+                               cur.posBackward();
+               }
        }
 
        // Optimisation: this is used in the next two loops
@@ -707,6 +716,8 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
 }
 
 
+#if 0
+// Not used, see TextMetrics::rowBreakPoint. 
 // this needs special handling - only newlines count as a break point
 static pos_type addressBreakPoint(pos_type i, Paragraph const & par)
 {
@@ -718,6 +729,7 @@ static pos_type addressBreakPoint(pos_type i, Paragraph const & par)
 
        return end;
 }
+#endif
 
 
 int TextMetrics::labelEnd(pit_type const pit) const
@@ -1386,7 +1398,8 @@ pit_type TextMetrics::getPitNearY(int y)
        int yy = -1;
        ParMetricsCache::const_iterator it = par_metrics_.begin();
        ParMetricsCache::const_iterator et = par_metrics_.end();
-       ParMetricsCache::const_iterator last = et; last--;
+       ParMetricsCache::const_iterator last = et;
+       --last;
 
        ParagraphMetrics const & pm = it->second;