X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=09cedf8c4489d8313997c1ded4852fd3c3680813;hb=0fa93fe55a85e901215ea783e3baf2b465fb67bd;hp=f002de009a9d666d0c10b04eb8df8cba5d4be28a;hpb=6dd990560e439dd8a1c07230519033253e1ce77c;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index f002de009a..09cedf8c44 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -1087,19 +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()); - // Replace (column-separating) tabs by space (#4449) - docstring const clean_text = subst(plaintext, '\t', ' '); - par.insert(0, clean_text, 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);