if (parlist.empty())
return PasteReturnValue(pit, pos, need_update);
+ // Check whether we paste into an inset that does not
+ // produce output (needed for label duplicate check)
+ bool in_active_inset = cur.paragraph().inInset().producesOutput();
+ if (in_active_inset) {
+ for (size_type sl = 0 ; sl < cur.depth() ; ++sl) {
+ Paragraph const & outer_par = cur[sl].paragraph();
+ if (!outer_par.inInset().producesOutput()) {
+ in_active_inset = false;
+ break;
+ }
+ }
+ }
+
InsetText * target_inset = cur.inset().asInsetText();
if (!target_inset) {
InsetTabular * it = cur.inset().asInsetTabular();
- target_inset = it ? it->cell(cur.idx())->asInsetText() : 0;
+ target_inset = it ? it->cell(cur.idx())->asInsetText() : nullptr;
}
LASSERT(target_inset, return PasteReturnValue(pit, pos, need_update));
// Now remove all out of the pars which is NOT allowed in the
// new environment and set also another font if that is required.
+ // Merge paragraphs that are to be pasted into a text inset
+ // that does not allow multiple pars.
+ InsetText * inset_text = target_inset->asInsetText();
+ if (inset_text && !inset_text->allowMultiPar()) {
+ while (insertion.size() > 1)
+ mergeParagraph(buffer.params(), insertion, 0);
+ }
+
// Convert newline to paragraph break in ParbreakIsNewline
if (target_inset->getLayout().parbreakIsNewline()
|| pars[pit].layout().parbreak_is_newline) {
tmpbuf->eraseChar(i--, false);
}
- tmpbuf->setChange(Change(buffer.params().track_changes ?
- Change::INSERTED : Change::UNCHANGED));
+ if (lyxrc.ct_markup_copied)
+ tmpbuf->setChange(Change(buffer.params().track_changes ?
+ Change::INSERTED : Change::UNCHANGED));
}
bool const empty = pars[pit].empty();
InsetIterator const i_end = inset_iterator_end(in);
for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
// Even though this will also be done later, it has to be done here
- // since some inset might going to try to access
- // the buffer() member.
+ // since some inset might try to access the buffer() member.
it->setBuffer(const_cast<Buffer &>(buffer));
switch (it->lyxCode()) {
continue;
InsetLabel * lab = labels[i];
docstring const oldname = lab->getParam("name");
- lab->updateLabel(oldname);
+ lab->updateLabel(oldname, in_active_inset);
// We need to update the buffer reference cache.
need_update = true;
docstring const newname = lab->getParam("name");
// check for duplicates
InsetLabel & lab = static_cast<InsetLabel &>(*it);
docstring const oldname = lab.getParam("name");
- lab.updateLabel(oldname);
+ lab.updateLabel(oldname, in_active_inset);
// We need to update the buffer reference cache.
need_update = true;
docstring const newname = lab.getParam("name");
// Use a clone for the complicated stuff so that we do not need to clean
// up in order to avoid a crash.
Buffer * buffer = staticbuffer->cloneBufferOnly();
- LASSERT(buffer, return 0);
+ LASSERT(buffer, return nullptr);
// This needs doing every time.
// Since setDocumentClass() causes deletion of the old document class
void putClipboard(ParagraphList const & paragraphs,
- DocumentClassConstPtr docclass, docstring const & plaintext)
+ DocumentClassConstPtr docclass, docstring const & plaintext,
+ BufferParams const bp)
{
Buffer * buffer = copyToTempBuffer(paragraphs, docclass);
if (!buffer) // already asserted in copyToTempBuffer()
// applications, the number that can parse it should go up in the future.
buffer->params().html_math_output = BufferParams::MathML;
+ if (lyxrc.ct_markup_copied) {
+ // Copy authors to the params. We need those pointers.
+ for (Author const & a : bp.authors())
+ buffer->params().authors().record(a);
+ }
+
// Make sure MarkAsExporting is deleted before buffer is
{
// The Buffer is being used to export. This is necessary so that the
// do not copy text (also nested in insets) which is marked as
// deleted, unless the whole selection was deleted
- if (!isFullyDeleted(copy_pars))
- acceptChanges(copy_pars, buf.params());
- else
- rejectChanges(copy_pars, buf.params());
+ if (!lyxrc.ct_markup_copied) {
+ if (!isFullyDeleted(copy_pars))
+ acceptChanges(copy_pars, buf.params());
+ else
+ rejectChanges(copy_pars, buf.params());
+ }
// do some final cleanup now, to make sure that the paragraphs
it = copy_pars.begin();
for (; it != it_end; ++it) {
it->resetBuffer();
- it->setInsetOwner(0);
+ it->setInsetOwner(nullptr);
}
cutstack.push(make_pair(copy_pars, dc));
namespace {
-void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcut, bool putclip)
+void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool realcut, bool putclip)
{
// This doesn't make sense, if there is no selection
if (!cur.selection())
// Even if there is no selection.
if (putclip)
putClipboard(cuts[0].first, cuts[0].second,
- cur.selectionAsString(true));
+ cur.selectionAsString(true, true), bp);
}
if (begpit != endpit)
cur.pos() = endpos;
cur.pit() = endpit;
- // sometimes necessary
- if (doclear
- && text->paragraphs()[begpit].stripLeadingSpaces(bp.track_changes))
- cur.fixIfBroken();
-
// need a valid cursor. (Lgb)
cur.clearSelection();
} // namespace
-void cutSelection(Cursor & cur, bool doclear, bool realcut)
+void cutSelection(Cursor & cur, bool realcut)
{
- cutSelectionHelper(cur, theCuts, doclear, realcut, true);
+ cutSelectionHelper(cur, theCuts, realcut, true);
}
-void cutSelectionToTemp(Cursor & cur, bool doclear, bool realcut)
+void cutSelectionToTemp(Cursor & cur, bool realcut)
{
- cutSelectionHelper(cur, tempCut, doclear, realcut, false);
+ cutSelectionHelper(cur, tempCut, realcut, false);
}
void copySelection(Cursor const & cur)
{
- copySelection(cur, cur.selectionAsString(true));
+ copySelection(cur, cur.selectionAsString(true, true));
}
theCuts.push(make_pair(pars, bp.documentClassPtr()));
// stuff the selection onto the X clipboard, from an explicit copy request
- putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
+ putClipboard(theCuts[0].first, theCuts[0].second, plaintext, bp);
}
}
+void copySelectionToTemp(Cursor & cur)
+{
+ copySelectionToStack(cur, tempCut);
+}
+
+
void copySelection(Cursor const & cur, docstring const & plaintext)
{
// In tablemode, because copy and paste actually use special table stack
}
// stuff the selection onto the X clipboard, from an explicit copy request
- putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
+ putClipboard(theCuts[0].first, theCuts[0].second, plaintext,
+ cur.buffer()->params());
}
if (cur.selection()
&& cur.selBegin() == cur.bv().cursor().selBegin()
&& cur.selEnd() == cur.bv().cursor().selEnd()) {
- LYXERR(Debug::SELECTION, "saveSelection: '" << cur.selectionAsString(true) << "'");
+ LYXERR(Debug::SELECTION, "saveSelection: '" << cur.selectionAsString(true, true) << "'");
copySelectionToStack(cur, selectionBuffer);
}
}
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
- DocumentClassConstPtr docclass, ErrorList & errorList,
- cap::BranchAction branchAction)
+ DocumentClassConstPtr docclass, ErrorList & errorList,
+ cap::BranchAction branchAction)
{
if (cur.inTexted()) {
Text * text = cur.text();
return;
cur.recordUndo();
- cutSelection(cur, true, false);
+ cutSelection(cur, false);
if (asParagraphs)
cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
else
par.insertChar(pos, *cit, font, cur.buffer()->params().track_changes);
// Cut the selection
- cutSelection(cur, true, false);
+ cutSelection(cur, false);
}
void replaceSelection(Cursor & cur)
{
if (cur.selection())
- cutSelection(cur, true, false);
+ cutSelection(cur, false);
}