Layout const & layout = cpar.layout();
if (cur.lastpos() == 0 && !cpar.allowEmpty()) {
- if (changeDepthAllowed(cur, DEC_DEPTH))
+ if (changeDepthAllowed(cur, DEC_DEPTH)) {
changeDepth(cur, DEC_DEPTH);
- else {
+ pit_type const prev = depthHook(cpit, cpar.getDepth());
+ docstring const & lay = pars_[prev].layout().name();
+ if (lay != layout.name())
+ setLayout(cur, lay);
+ } else {
docstring const & lay = cur.paragraph().usePlainLayout()
? tclass.plainLayoutName() : tclass.defaultLayoutName();
if (lay != layout.name())
Paragraph const & par = pars_[pit];
bool lastpar = (pit == pit_type(pars_.size() - 1));
Paragraph const & nextpar = lastpar ? par : pars_[pit + 1];
- pit_type prev = pit;
- if (pit > 0) {
- if (!pars_[pit - 1].layout().isEnvironment())
- prev = depthHook(pit, par.getDepth());
- else if (pars_[pit - 1].getDepth() >= par.getDepth())
- prev = pit - 1;
- }
+ pit_type prev = pit > 0 ? depthHook(pit, par.getDepth()) : pit;
if (prev < pit && cur.pos() == par.beginOfBody()
&& !par.size() && !par.isEnvSeparator(cur.pos())
&& !par.layout().isCommand()