]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Micro-optimization.
[lyx.git] / src / Text.cpp
index 66c6090aa22c9abb40d8d9561fcdf82ddb7cbcb2..20accf5562f9efb81d2b5322c568347a48eea4c2 100644 (file)
@@ -170,19 +170,12 @@ void mergeParagraph(BufferParams const & bparams,
        pars.erase(boost::next(pars.begin(), par_offset + 1));
 }
 
-// Initialization of the counter for the paragraph id's,
-//
-// FIXME: There should be a more intelligent way to generate and use the
-// paragraph ids per buffer instead a global static counter for all InsetText
-// in the running program.
-static int paragraph_id = -1;
 
 Text::Text(InsetText * owner, bool use_default_layout)
        : owner_(owner), autoBreakRows_(false), undo_counter_(0)
 {
        pars_.push_back(Paragraph());
        Paragraph & par = pars_.back();
-       par.setId(++paragraph_id);
        par.setInsetOwner(owner);
        DocumentClass const & dc = owner->buffer().params().documentClass();
        if (use_default_layout)
@@ -198,10 +191,8 @@ Text::Text(InsetText * owner, Text const & text)
        pars_ = text.pars_;
        ParagraphList::iterator const end = pars_.end();
        ParagraphList::iterator it = pars_.begin();
-       for (; it != end; ++it) {
-               it->setId(++paragraph_id);
+       for (; it != end; ++it)
                it->setInsetOwner(owner);
-       }
 }
 
 
@@ -674,11 +665,13 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
        DocumentClass const & tclass = cur.buffer()->params().documentClass();
        Layout const & layout = cpar.layout();
 
-       // this is only allowed, if the current paragraph is not empty
-       // or caption and if it has not the keepempty flag active
-       if (cur.lastpos() == 0 && !cpar.allowEmpty() &&
-           layout.labeltype != LABEL_SENSITIVE)
+       if (cur.lastpos() == 0 && !cpar.allowEmpty()) {
+               if (changeDepthAllowed(cur, DEC_DEPTH))
+                       changeDepth(cur, DEC_DEPTH);
+               else 
+                       setLayout(cur, tclass.defaultLayoutName());
                return;
+       }
 
        // a layout change may affect also the following paragraph
        recUndo(cur, cur.pit(), undoSpan(cur.pit()) - 1);
@@ -724,7 +717,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
                        break; // the character couldn't be deleted physically due to change tracking
        }
 
-       cur.buffer()->updateLabels();
+       cur.buffer()->updateBuffer();
 
        // A singlePar update is not enough in this case.
        cur.updateFlags(Update::Force);
@@ -1301,7 +1294,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
        cur.clearSelection();
        setCursorIntern(cur, begPit, begPos);
        cur.updateFlags(Update::Force);
-       cur.buffer()->updateLabels();
+       cur.buffer()->updateBuffer();
 }
 
 
@@ -1452,7 +1445,7 @@ bool Text::handleBibitems(Cursor & cur)
                cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
                mergeParagraph(bufparams, cur.text()->paragraphs(),
                                                        prevcur.pit());
-               cur.buffer()->updateLabels();
+               cur.buffer()->updateBuffer();
                setCursorIntern(cur, prevcur.pit(), prevcur.pos());
                cur.updateFlags(Update::Force);
                return true;
@@ -1480,7 +1473,7 @@ bool Text::erase(Cursor & cur)
                        cur.top().forwardPos();
 
                if (was_inset)
-                       cur.buffer()->updateLabels();
+                       cur.buffer()->updateBuffer();
                else
                        cur.checkBufferStructure();
                needsUpdate = true;
@@ -1556,7 +1549,7 @@ bool Text::backspacePos0(Cursor & cur)
        }
 
        if (needsUpdate) {
-               cur.buffer()->updateLabels();
+               cur.buffer()->updateBuffer();
                setCursorIntern(cur, prevcur.pit(), prevcur.pos());
        }
 
@@ -1596,7 +1589,7 @@ bool Text::backspace(Cursor & cur)
                bool const was_inset = cur.paragraph().isInset(cur.pos());
                cur.paragraph().eraseChar(cur.pos(), cur.buffer()->params().trackChanges);
                if (was_inset)
-                       cur.buffer()->updateLabels();
+                       cur.buffer()->updateBuffer();
                else
                        cur.checkBufferStructure();
        }
@@ -1654,7 +1647,7 @@ bool Text::dissolveInset(Cursor & cur)
        } else
                // this is the least that needs to be done (bug 6003)
                // in the above case, pasteParagraphList handles this
-               cur.buffer()->updateLabels();
+               cur.buffer()->updateBuffer();
 
        // Ensure the current language is set correctly (bug 6292)
        cur.text()->setCursor(cur, cur.pit(), cur.pos());