diff --git a/src/Text.cpp b/src/Text.cpp index a6176bc08a..36d0decf73 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -764,9 +764,13 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic) 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()) diff --git a/src/Text3.cpp b/src/Text3.cpp index bfb5d7953e..45cc7637c5 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1088,13 +1088,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) 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()