Change::INSERTED : Change::UNCHANGED));
}
- bool const empty = pars[pit].empty();
- if (!empty) {
- // Make the buf exactly the same layout as the cursor
- // paragraph.
+ bool const target_empty = pars[pit].empty();
+ // Use the paste content's layout, if...
+ bool const paste_layout =
+ // if target paragraph is empty
+ (target_empty
+ // ... and its layout is default
+ && (pars[pit].layout() == defaultLayout
+ // ... or plain
+ || pars[pit].layout() == plainLayout
+ // ... or the paste content spans several paragraphs
+ || insertion.size() > 1))
+ // or if pasting is done at the beginning of paragraph
+ || (pos == 0
+ // and the paste content spans several paragraphs
+ && insertion.size() > 1);
+ if (!paste_layout)
+ // Give the first paragraph to insert the same layout as the
+ // target paragraph.
insertion.begin()->makeSameLayout(pars[pit]);
- }
// Prepare the paragraphs and insets for insertion.
insertion.swap(in.paragraphs());
insertion.swap(in.paragraphs());
// Split the paragraph for inserting the buf if necessary.
- if (!empty)
+ if (!target_empty)
breakParagraphConservative(buffer.params(), pars, pit, pos);
+ // If multiple paragraphs are inserted before the target paragraph,
+ // the cursor is now in a new paragraph before it,
+ // so use layout from paste content in that case.
+ if (pos == 0 && insertion.size() > 1)
+ pars[pit].makeSameLayout(* insertion.begin());
+
// Paste it!
- if (empty) {
+ if (target_empty) {
pars.insert(pars.iterator_at(pit),
insertion.begin(), insertion.end());
// Join (conditionally) last pasted paragraph with next one, i.e.,
// the tail of the spliced document paragraph
- if (!empty && last_paste + 1 != pit_type(pars.size())) {
+ if (!target_empty && last_paste + 1 != pit_type(pars.size())) {
if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
mergeParagraph(buffer.params(), pars, last_paste);
} else if (pars[last_paste + 1].empty()) {
}
+void switchBetweenClasses(DocumentClassConstPtr oldone,
+ DocumentClassConstPtr newone, InsetText & in) {
+ ErrorList el = {};
+ switchBetweenClasses(oldone, newone, in, el);
+}
+
+
void switchBetweenClasses(DocumentClassConstPtr oldone,
DocumentClassConstPtr newone, InsetText & in, ErrorList & errorlist)
{
docstring const & n = newone->insetLayout(layoutName).name();
bool const is_undefined = n.empty() ||
n == DocumentClass::plainInsetLayout().name();
- if (!is_undefined)
+ docstring const & oldn = oldone->insetLayout(layoutName).name();
+ bool const was_undefined = oldn.empty() ||
+ oldn == DocumentClass::plainInsetLayout().name();
+ if (!is_undefined || was_undefined)
continue;
// The flex inset is undefined in newtc
string lyx = theClipboard().getAsLyX();
if (!lyx.empty()) {
Buffer buffer(string(), false);
+ buffer.setInternal(true);
buffer.setUnnamed(true);
if (buffer.readString(lyx)) {
cur.recordUndo();
available = !text.empty();
if (available) {
Buffer buffer(string(), false);
+ buffer.setInternal(true);
buffer.setUnnamed(true);
+ buffer.params() = cur.buffer()->params();
available = buffer.importString(names[i], text, errorList);
if (available)
available = !buffer.paragraphs().empty();