Le 24/08/2019 à 07:49, Daniel a écrit :
Currently, IMO, notes behave in an unfortunate way in that they inherit the surrounding font.

Consider the attached document which has the following structure:

*Section*
Text

The first line is formatted as a section heading and the second as standard text.

In Lyx, select all text in the document and insert a note.

The actual result is that all the text looks as if it where formatted as section. This is misleading. It is also in many cases annoying. For example, when adding a longer note to a section heading it becomes huge.

This is not misleading. This indicates that your note is actuall embedded in a paragraph with style Section, so that the empty paragraph will be output as
  \section{]

This is the behavior that we shall fix.

I propose in the following patch to reset the outer layout to Plain if it only contains the newly insert inset.

I'd appreciate if somebody could try t out to see whether I missed something obvious. This behavior has been annoying me for ages and I am sure we have several bug reports about that.

JMarc

From 68872c28ebf8c479e08580d4b5f785f5c99f9561 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Wed, 4 Sep 2019 16:13:22 +0200
Subject: [PATCH] Reset layout when inserting an inset over full paragraph(s)

When inserting an inset over a selection, it makes sense if the
selection covers a complete or several paragraphs to reset the layout of
the paragraph that contains the inset to plain layout. In general the
inner inset will have the needed layout information and it does not
make sense to keep this information outside.

Note that this does not work as intended when change tracking is enabled.
---
 src/Text3.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/Text3.cpp b/src/Text3.cpp
index 57d44a1..0ba8083 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -293,11 +293,22 @@ static bool doInsertInset(Cursor & cur, Text * text,
 	}
 
 	bool gotsel = false;
+	bool reset_layout = false;
 	if (cur.selection()) {
 		if (cmd.action() == LFUN_INDEX_INSERT)
 			copySelectionToTemp(cur);
-		else
+		else {
 			cutSelectionToTemp(cur, pastesel);
+			/* No need to keep layout information if the inset has
+			 * eaten the whole paragraph.
+			 * FIXME: this does not work as expected when change tracking is on
+			 *   However, we do not really know what to do in this case.
+			 */
+			if (cur.paragraph().empty()) {
+				cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass());
+				reset_layout = true;
+			}
+		}
 		cur.clearSelection();
 		gotsel = true;
 	} else if (cmd.action() == LFUN_INDEX_INSERT) {
@@ -320,7 +331,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
 	InsetText * inset_text = inset->asInsetText();
 	if (inset_text) {
 		inset_text->fixParagraphsFont();
-		if (!inset_text->allowMultiPar() || cur.lastpit() == 0) {
+		if (!inset_text->allowMultiPar()
+		    || (cur.lastpit() == 0 && !reset_layout)) {
 			// reset first par to default
 			cur.text()->paragraphs().begin()
 				->setPlainOrDefaultLayout(bparams.documentClass());
-- 
2.7.4

Reply via email to