Fix indentation of paragraphs after an environment.

When deciding whether a paragraph should be indented or not, LyX
only takes into account default layouts. This is wrong, because
an environment could be nested into another one and thus a following
paragraph would not be "default". With this patch all paragraphs
after an environment are correctly indented, independently of
whether their layouts are "default" or not.
The latex output (which was modeled following the previous wrong
assumption) is also correspondingly adapted.

No status line needed as this is the completion of previous patches.
This commit is contained in:
Enrico Forestieri 2014-05-28 22:16:40 +02:00
parent f40adfd486
commit a640f4244e
2 changed files with 16 additions and 14 deletions

View File

@ -1894,7 +1894,9 @@ int TextMetrics::leftMargin(int max_width,
l_margin = leftMargin(max_width, newpar); l_margin = leftMargin(max_width, newpar);
// Remove the parindent that has been added // Remove the parindent that has been added
// if the paragraph was empty. // if the paragraph was empty.
if (pars[newpar].empty()) { if (pars[newpar].empty() &&
buffer.params().paragraph_separation ==
BufferParams::ParagraphIndentSeparation) {
docstring pi = pars[newpar].layout().parindent; docstring pi = pars[newpar].layout().parindent;
l_margin -= theFontMetrics( l_margin -= theFontMetrics(
buffer.params().getFont()).signedWidth(pi); buffer.params().getFont()).signedWidth(pi);
@ -1912,10 +1914,16 @@ int TextMetrics::leftMargin(int max_width,
// This happens after sections or environments in standard classes. // This happens after sections or environments in standard classes.
// We have to check the previous layout at same depth. // We have to check the previous layout at same depth.
if (tclass.isDefaultLayout(par.layout()) && pit > 0 if (buffer.params().paragraph_separation ==
&& pars[pit - 1].getDepth() >= par.getDepth()) { BufferParams::ParagraphSkipSeparation)
parindent.erase();
else if (pit > 0 && pars[pit - 1].getDepth() >= par.getDepth()) {
pit_type prev = text_->depthHook(pit, par.getDepth()); pit_type prev = text_->depthHook(pit, par.getDepth());
if (pars[prev < pit ? prev : pit - 1].layout().nextnoindent) if (par.layout() == pars[prev].layout()) {
if (prev != pit - 1
&& pars[pit - 1].layout().nextnoindent)
parindent.erase();
} else if (pars[prev].layout().nextnoindent)
parindent.erase(); parindent.erase();
} }

View File

@ -198,9 +198,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
} }
static void finishEnvironment(Buffer const & buf, Text const & text, static void finishEnvironment(otexstream & os, OutputParams const & runparams,
pit_type nextpit, otexstream & os,
OutputParams const & runparams,
TeXEnvironmentData const & data) TeXEnvironmentData const & data)
{ {
if (open_encoding_ == CJK && data.cjk_nested) { if (open_encoding_ == CJK && data.cjk_nested) {
@ -231,11 +229,7 @@ static void finishEnvironment(Buffer const & buf, Text const & text,
} }
// Check whether we should output a blank line after the environment // Check whether we should output a blank line after the environment
DocumentClass const & tclass = buf.params().documentClass(); if (!data.style->nextnoindent)
ParagraphList const & pars = text.paragraphs();
bool next_style_is_default = (nextpit >= runparams.par_end) ? false
: tclass.isDefaultLayout(pars.constIterator(nextpit)->layout());
if (!data.style->nextnoindent && next_style_is_default)
os << '\n'; os << '\n';
} }
@ -316,7 +310,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
prepareEnvironment(buf, text, par, os, runparams); prepareEnvironment(buf, text, par, os, runparams);
// Recursive call to TeXEnvironment! // Recursive call to TeXEnvironment!
TeXEnvironment(buf, text, runparams, pit, os); TeXEnvironment(buf, text, runparams, pit, os);
finishEnvironment(buf, text, pit + 1, os, runparams, data); finishEnvironment(os, runparams, data);
} }
if (pit != runparams.par_end) if (pit != runparams.par_end)
@ -1164,7 +1158,7 @@ void latexParagraphs(Buffer const & buf,
prepareEnvironment(buf, text, par, os, runparams); prepareEnvironment(buf, text, par, os, runparams);
// pit can be changed in TeXEnvironment. // pit can be changed in TeXEnvironment.
TeXEnvironment(buf, text, runparams, pit, os); TeXEnvironment(buf, text, runparams, pit, os);
finishEnvironment(buf, text, pit + 1, os, runparams, data); finishEnvironment(os, runparams, data);
} }
if (pit == runparams.par_end) { if (pit == runparams.par_end) {