X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=09cedf8c4489d8313997c1ded4852fd3c3680813;hb=0fa93fe55a85e901215ea783e3baf2b465fb67bd;hp=0e620aab8ace717858849652b242a27c9475145d;hpb=8d26ae57ba66b4518985cf3430de2dcf37096568;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 0e620aab8a..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 @@ -887,8 +885,6 @@ vector availableSelections(Buffer const * buf) return selList; for (auto const & cut : theCuts) { - // we do not use cit-> here because gcc 2.9x does not - // like it (JMarc) ParagraphList const & pars = cut.first; docstring textSel; for (auto const & para : pars) { @@ -1091,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); @@ -1221,9 +1242,7 @@ bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs, theClipboard().hasTextContents(Clipboard::LyXTextType)) { string lyx = theClipboard().getAsLyX(); if (!lyx.empty()) { - // For some strange reason gcc 3.2 and 3.3 do not accept - // Buffer buffer(string(), false); - Buffer buffer("", false); + Buffer buffer(string(), false); buffer.setUnnamed(true); if (buffer.readString(lyx)) { cur.recordUndo(); @@ -1254,9 +1273,7 @@ bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs, docstring text = theClipboard().getAsText(types[i]); available = !text.empty(); if (available) { - // For some strange reason gcc 3.2 and 3.3 do not accept - // Buffer buffer(string(), false); - Buffer buffer("", false); + Buffer buffer(string(), false); buffer.setUnnamed(true); available = buffer.importString(names[i], text, errorList); if (available) @@ -1364,8 +1381,10 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str) // Insert the new string pos_type pos = cur.selEnd().pos(); Paragraph & par = cur.selEnd().paragraph(); - for (auto const & c : str) + for (auto const & c : str) { par.insertChar(pos, c, font, cur.buffer()->params().track_changes); + ++pos; + } // Cut the selection cutSelection(cur, false);