Le 19/10/2016 à 18:12, Enrico Forestieri a écrit :
I had a look and it turns out that the code dealing with separator
insets was specifically tailored to the old behaviour. If you change
that behaviour, you should also change the corresponding separator code.
This is what the attached patch does. It must be applied if your patch
is applied, otherwise not.

Anyway, the previous behaviour was really strange and indeed also
the code to be changed for introducing a separator simplifies, as
you can see.

Thanks, it seems to work well. Here is the combo commit, for reference. I propose to commit it to master and maybe branch (Richard?), so that we can evaluate whether we like it.

JMarc

>From 72f680d1d03acc52f57dd4873a676484a1927c49 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Thu, 13 Oct 2016 20:33:57 +0200
Subject: [PATCH] When breaking an empty paragraph reduces depth, set layout
 too

This requires an adaptation of the Separator inset insertion code,
which has been duly provided by Enrico.
---
 src/Text.cpp  |    8 ++++++--
 src/Text3.cpp |    8 +-------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/Text.cpp b/src/Text.cpp
index 007271d..16bf899 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -738,9 +738,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 eafce28..85d0c3c 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1089,13 +1089,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()
-- 
1.7.9.5

Reply via email to