diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index cc3d5fe026..5c104dcc56 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1998,7 +1998,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) Buffer * const b = newFile(filename, templname, !name.empty()); if (b) { - //updateLabels(*b); + updateLabels(*b); lyx_view_->setBuffer(b); } } diff --git a/src/Text.cpp b/src/Text.cpp index 3fd04c724f..abd71961a6 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -344,6 +344,13 @@ void readParagraph(Buffer const & buf, Paragraph & par, Lexer & lex, } // namespace anon +bool Text::empty() const +{ + return pars_.empty() || (pars_.size() == 1 && pars_[0].empty() + // FIXME: Should we consider the labeled type as empty too? + && pars_[0].layout()->labeltype == LABEL_NO_LABEL); +} + double Text::spacing(Buffer const & buffer, Paragraph const & par) const diff --git a/src/Text.h b/src/Text.h index a8ee899dca..7e154388a9 100644 --- a/src/Text.h +++ b/src/Text.h @@ -49,6 +49,11 @@ public: /// constructor explicit Text(); + /// \return true if there's no content at all. + /// \warning a non standard layout on an empty paragraph doesn't + // count as empty. + bool empty() const; + /// Font getFont(Buffer const & buffer, Paragraph const & par, pos_type pos) const; diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 84b037e67c..85044361a7 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -578,6 +578,8 @@ void updateLabels(Buffer const & buf, ParIterator & parit) } +// FIXME: buf should should be const because updateLabels() modifies +// the contents of the paragraphs. void updateLabels(Buffer const & buf, bool childonly) { Buffer const * const master = buf.getMasterBuffer(); @@ -595,11 +597,20 @@ void updateLabels(Buffer const & buf, bool childonly) textclass.counters().reset(); } + Buffer & cbuf = const_cast(buf); + + if (buf.text().empty()) { + // FIXME: we don't call continue with updateLabels() here because + // it crashes on newly created documents. But the TocBackend needs to + // be initialised nonetheless so we update the tocBackend manually. + cbuf.tocBackend().update(); + return; + } + // do the real work ParIterator parit = par_iterator_begin(buf.inset()); updateLabels(buf, parit); - Buffer & cbuf = const_cast(buf); cbuf.tocBackend().update(); if (!childonly) cbuf.structureChanged();