From e1be71da59e405a1c36769121b684c9d10333bff Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 4 Sep 2019 16:13:22 +0200 Subject: [PATCH] Reset layout when inserting an inset over full paragraph(s) 1/ 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. However, when the inset forces plain layout, it does not make sense to do that and the outer layout is preserved. Some code that duplicates what is done in pasteSelectionHelper is also removed. 2/ Similarly, when dissolving an inset, do not reset the layout of the first paragraph if the inset was alone in its own paragraph. Note that this does not work as intended when change tracking is enabled. Fixes bugs #10266 and #10369. --- src/Text.cpp | 10 ++++++++++ src/Text3.cpp | 39 ++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index 98cedccf9c..5e06fdccd1 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1820,6 +1820,16 @@ bool Text::dissolveInset(Cursor & cur) for (; it != it_end; ++it) it->changeLanguage(b.params(), latex_language, b.language()); + /* the inset is the only thing in paragraph, then the layout + * of the first paragraph of inset should be remembered. + * 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 (inset_it.lastpos() == 1 + && inset_it.nextInset() && !inset_it.nextInset()->forcePlainLayout()) + cur.paragraph().makeSameLayout(plist[0]); + pasteParagraphList(cur, plist, b.params().documentClassPtr(), b.errorList("Paste")); } diff --git a/src/Text3.cpp b/src/Text3.cpp index 57d44a177f..a91660336b 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -296,8 +296,16 @@ static bool doInsertInset(Cursor & cur, Text * text, if (cur.selection()) { if (cmd.action() == LFUN_INDEX_INSERT) copySelectionToTemp(cur); - else + else { cutSelectionToTemp(cur, pastesel); + /* Move layout information inside the inset if the whole + * paragraph and the inset allows setting layout + * 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() && !inset->forcePlainLayout()) + cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass()); + } cur.clearSelection(); gotsel = true; } else if (cmd.action() == LFUN_INDEX_INSERT) { @@ -320,24 +328,17 @@ 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) { - // reset first par to default - cur.text()->paragraphs().begin() - ->setPlainOrDefaultLayout(bparams.documentClass()); - cur.pos() = 0; - cur.pit() = 0; - // Merge multiple paragraphs -- hack - while (cur.lastpit() > 0) - mergeParagraph(bparams, cur.text()->paragraphs(), 0); - if (cmd.action() == LFUN_FLEX_INSERT) - return true; - Cursor old = cur; - cur.leaveInset(*inset); - if (cmd.action() == LFUN_PREVIEW_INSERT - || cmd.action() == LFUN_IPA_INSERT) - // trigger preview - notifyCursorLeavesOrEnters(old, cur); - } + cur.pos() = 0; + cur.pit() = 0; + // FIXME: what does this do? + if (cmd.action() == LFUN_FLEX_INSERT) + return true; + Cursor old = cur; + cur.leaveInset(*inset); + if (cmd.action() == LFUN_PREVIEW_INSERT + || cmd.action() == LFUN_IPA_INSERT) + // trigger preview + notifyCursorLeavesOrEnters(old, cur); } else { cur.leaveInset(*inset); // reset surrounding par to default