]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
unneeded header
[lyx.git] / src / text.C
index fc23249c0e4f05f9b34efe63ebe7fdff65469408..a0a3c05f83bb3ed35115edd7e21222b97ea12dc0 100644 (file)
@@ -1458,6 +1458,8 @@ bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
 
 void LyXText::acceptChange(LCursor & cur)
 {
+       // FIXME: change tracking (MG)
+
        BOOST_ASSERT(this == cur.text());
 
        if (!cur.selection() && cur.lastpos() != 0)
@@ -1470,25 +1472,17 @@ void LyXText::acceptChange(LCursor & cur)
        DocIterator it = cur.selectionBegin();
        DocIterator et = cur.selectionEnd();
        pit_type pit = it.pit();
-       bool isDeleted = pars_[pit].isDeleted(it.pos());
        for (; pit <= et.pit(); ++pit) {
-               pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
-               pos_type right =
-                   ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
+               pos_type left  = (pit == it.pit() ? it.pos() : 0);
+               pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
                pars_[pit].acceptChanges(left, right);
-       }
-       if (isDeleted) {
-               ParagraphList & plist = paragraphs();
-               if (it.pit() + 1 < et.pit())
-                       pars_.erase(boost::next(plist.begin(), it.pit() + 1),
-                                   boost::next(plist.begin(), et.pit()));
 
-               // Paragraph merge if appropriate:
-               // FIXME: change tracking (MG)
-               if (pars_[it.pit()].isDeleted(pars_[it.pit()].size())) {
-                       setCursorIntern(cur, it.pit() + 1, 0);
-                       backspacePos0(cur);
-               }
+               // merge paragraph if appropriate:
+               // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
+               //    pars_[pit].isDeleted(pars_[pit].size())) {
+               //      setCursorIntern(cur, pit + 1, 0);
+               //      backspacePos0(cur);
+               //}
        }
        finishUndo();
        cur.clearSelection();
@@ -1498,6 +1492,8 @@ void LyXText::acceptChange(LCursor & cur)
 
 void LyXText::rejectChange(LCursor & cur)
 {
+       // FIXME: change tracking (MG)
+
        BOOST_ASSERT(this == cur.text());
 
        if (!cur.selection() && cur.lastpos() != 0)
@@ -1510,24 +1506,17 @@ void LyXText::rejectChange(LCursor & cur)
        DocIterator it = cur.selectionBegin();
        DocIterator et = cur.selectionEnd();
        pit_type pit = it.pit();
-       bool isInserted = pars_[pit].isInserted(it.pos());
        for (; pit <= et.pit(); ++pit) {
-               pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
-               pos_type right =
-                   ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
+               pos_type left  = (pit == it.pit() ? it.pos() : 0);
+               pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
                pars_[pit].rejectChanges(left, right);
-       }
-       if (isInserted) {
-               ParagraphList & plist = paragraphs();
-               if (it.pit() + 1 < et.pit())
-                       pars_.erase(boost::next(plist.begin(), it.pit() + 1),
-                                   boost::next(plist.begin(), et.pit()));
-               // Paragraph merge if appropriate:
-               // FIXME: change tracking (MG)
-               if (pars_[it.pit()].isInserted(pars_[it.pit()].size())) {
-                       setCursorIntern(cur, it.pit() + 1, 0);
-                       backspacePos0(cur);
-               }
+
+               // merge paragraph if appropriate:      
+               // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
+               //    pars_[pit].isInserted(pars_[pit].size())) {
+               //      setCursorIntern(cur, pit + 1, 0);
+               //      backspacePos0(cur);
+               //}
        }
        finishUndo();
        cur.clearSelection();
@@ -1844,6 +1833,8 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
        Paragraph & par = pars_[pit];
        Buffer const & buffer = *bv.buffer();
 
+       bool changed = false;
+
        // Add bibitem insets if necessary
        if (par.layout()->labeltype == LABEL_BIBLIO) {
                bool hasbibitem(false);
@@ -1882,7 +1873,7 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
                        bufferfont :
                        getFont(buffer, par, ii->pos);
                MetricsInfo mi(&bv, font, w);
-               ii->inset->metrics(mi, dim);
+               changed |= ii->inset->metrics(mi, dim);
        }
 
        // rebreak the paragraph
@@ -1919,16 +1910,16 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
        dim.asc += par.rows()[0].ascent();
        dim.des -= par.rows()[0].ascent();
 
-       bool const same = dim.height() == par.dim().height();
+       changed |= dim.height() != par.dim().height();
 
        par.dim() = dim;
        //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
 
-       return !same;
+       return changed;
 }
 
 
-void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
+bool LyXText::metrics(MetricsInfo & mi, Dimension & dim)
 {
        //BOOST_ASSERT(mi.base.textwidth);
        if (mi.base.textwidth)
@@ -1938,10 +1929,12 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
        // save the caller's font locally:
        font_ = mi.base.font;
 
+       bool changed = false;
+
        unsigned int h = 0;
        unsigned int w = 0;
        for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) {
-               redoParagraph(*mi.base.bv, pit);
+               changed |= redoParagraph(*mi.base.bv, pit);
                Paragraph & par = paragraphs()[pit];
                h += par.height();
                if (w < par.width())
@@ -1952,7 +1945,9 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
        dim.asc = pars_[0].ascent();
        dim.des = h - dim.asc;
 
+       changed |= dim_ != dim;
        dim_ = dim;
+       return changed;
 }