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.
This commit is contained in:
Jean-Marc Lasgouttes 2019-09-04 16:13:22 +02:00
parent d76cef70a0
commit e1be71da59
2 changed files with 30 additions and 19 deletions

View File

@ -1820,6 +1820,16 @@ bool Text::dissolveInset(Cursor & cur)
for (; it != it_end; ++it) for (; it != it_end; ++it)
it->changeLanguage(b.params(), latex_language, b.language()); 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(), pasteParagraphList(cur, plist, b.params().documentClassPtr(),
b.errorList("Paste")); b.errorList("Paste"));
} }

View File

@ -296,8 +296,16 @@ static bool doInsertInset(Cursor & cur, Text * text,
if (cur.selection()) { if (cur.selection()) {
if (cmd.action() == LFUN_INDEX_INSERT) if (cmd.action() == LFUN_INDEX_INSERT)
copySelectionToTemp(cur); copySelectionToTemp(cur);
else else {
cutSelectionToTemp(cur, pastesel); 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(); cur.clearSelection();
gotsel = true; gotsel = true;
} else if (cmd.action() == LFUN_INDEX_INSERT) { } else if (cmd.action() == LFUN_INDEX_INSERT) {
@ -320,24 +328,17 @@ static bool doInsertInset(Cursor & cur, Text * text,
InsetText * inset_text = inset->asInsetText(); InsetText * inset_text = inset->asInsetText();
if (inset_text) { if (inset_text) {
inset_text->fixParagraphsFont(); inset_text->fixParagraphsFont();
if (!inset_text->allowMultiPar() || cur.lastpit() == 0) { cur.pos() = 0;
// reset first par to default cur.pit() = 0;
cur.text()->paragraphs().begin() // FIXME: what does this do?
->setPlainOrDefaultLayout(bparams.documentClass()); if (cmd.action() == LFUN_FLEX_INSERT)
cur.pos() = 0; return true;
cur.pit() = 0; Cursor old = cur;
// Merge multiple paragraphs -- hack cur.leaveInset(*inset);
while (cur.lastpit() > 0) if (cmd.action() == LFUN_PREVIEW_INSERT
mergeParagraph(bparams, cur.text()->paragraphs(), 0); || cmd.action() == LFUN_IPA_INSERT)
if (cmd.action() == LFUN_FLEX_INSERT) // trigger preview
return true; notifyCursorLeavesOrEnters(old, cur);
Cursor old = cur;
cur.leaveInset(*inset);
if (cmd.action() == LFUN_PREVIEW_INSERT
|| cmd.action() == LFUN_IPA_INSERT)
// trigger preview
notifyCursorLeavesOrEnters(old, cur);
}
} else { } else {
cur.leaveInset(*inset); cur.leaveInset(*inset);
// reset surrounding par to default // reset surrounding par to default