X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=09cedf8c4489d8313997c1ded4852fd3c3680813;hb=0fa93fe55a85e901215ea783e3baf2b465fb67bd;hp=c8c084a7aac39ff08d44ca21dfeb1c3a0bb6e573;hpb=c75674999127c58b5132e3ab713bd91bd88e75c6;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index c8c084a7aa..09cedf8c44 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -462,17 +462,15 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, // Paste it! if (empty) { - pars.insert(lyx::next(pars.begin(), pit), - insertion.begin(), - insertion.end()); + pars.insert(pars.iterator_at(pit), + insertion.begin(), insertion.end()); // merge the empty par with the last par of the insertion mergeParagraph(buffer.params(), pars, pit + insertion.size() - 1); } else { - pars.insert(lyx::next(pars.begin(), pit + 1), - insertion.begin(), - insertion.end()); + pars.insert(pars.iterator_at(pit + 1), + insertion.begin(), insertion.end()); // merge the first par of the insertion with the current par mergeParagraph(buffer.params(), pars, pit); @@ -604,7 +602,7 @@ Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPt void putClipboard(ParagraphList const & paragraphs, DocumentClassConstPtr docclass, docstring const & plaintext, - BufferParams const bp) + BufferParams const & bp) { Buffer * buffer = copyToTempBuffer(paragraphs, docclass); if (!buffer) // already asserted in copyToTempBuffer() @@ -683,8 +681,8 @@ void copySelectionHelper(Buffer const & buf, Text const & text, LASSERT(startpit != endpit || start <= end, return); // Clone the paragraphs within the selection. - ParagraphList copy_pars(lyx::next(pars.begin(), startpit), - lyx::next(pars.begin(), endpit + 1)); + ParagraphList copy_pars(pars.iterator_at(startpit), + pars.iterator_at(endpit + 1)); // Remove the end of the last paragraph; afterwards, remove the // beginning of the first paragraph. Keep this order - there may only @@ -1089,17 +1087,42 @@ void copySelectionToTemp(Cursor & cur) void copySelection(Cursor const & cur, docstring const & plaintext) { - // In tablemode, because copy and paste actually use special table stack - // we do not attempt to get selected paragraphs under cursor. Instead, a - // paragraph with the plain text version is generated so that table cells - // can be pasted as pure text somewhere else. + // In tablemode, because copy and paste actually use a special table stack, + // we need to go through the cells and collect the paragraphs. + // In math matrices, we generate a plain text version. if (cur.selBegin().idx() != cur.selEnd().idx()) { ParagraphList pars; - Paragraph par; BufferParams const & bp = cur.buffer()->params(); - par.setLayout(bp.documentClass().plainLayout()); - par.insert(0, plaintext, Font(), Change(Change::UNCHANGED)); - pars.push_back(par); + if (cur.inMathed()) { + Paragraph par; + par.setLayout(bp.documentClass().plainLayout()); + // Replace (column-separating) tabs by space (#4449) + docstring const clean_text = subst(plaintext, '\t', ' '); + // For pasting into text, we set the language to the paragraph language + // (rather than the default_language which is always English; see #11898) + par.insert(0, clean_text, Font(sane_font, par.getParLanguage(bp)), + Change(Change::UNCHANGED)); + pars.push_back(par); + } else { + // Get paragraphs from all cells + InsetTabular * table = cur.inset().asInsetTabular(); + LASSERT(table, return); + ParagraphList tplist = table->asParList(cur.selBegin().idx(), cur.selEnd().idx()); + for (auto & cpar : tplist) { + cpar.setLayout(bp.documentClass().plainLayout()); + pars.push_back(cpar); + // since the pars are merged later, we separate them by blank + Paragraph epar; + epar.insert(0, from_ascii(" "), Font(sane_font, epar.getParLanguage(bp)), + Change(Change::UNCHANGED)); + pars.push_back(epar); + } + // remove last empty par + pars.pop_back(); + // merge all paragraphs to one + while (pars.size() > 1) + mergeParagraph(bp, pars, 0); + } theCuts.push(make_pair(pars, bp.documentClassPtr())); } else { copySelectionToStack(cur, theCuts);