X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=6333892cd6cc6e2d1bfe6729a50657f46cc56fab;hb=51cc8aa9f6b784f806b1d9cc97fe0749ffac29af;hp=f41ce3641830e5d2be38e554440ee7737410e5ec;hpb=9c55af4a223ce4db29d643251109e245665344bd;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index f41ce36418..6333892cd6 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -480,8 +480,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params, } -void putClipboard(ParagraphList const & paragraphs, - DocumentClassConstPtr docclass, docstring const & plaintext) +Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPtr docclass) { // This used to need to be static to avoid a memory leak. It no longer needs // to be so, but the alternative is to construct a new one of these (with a @@ -500,7 +499,7 @@ void putClipboard(ParagraphList const & paragraphs, // 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); + LASSERT(buffer, return 0); // This needs doing every time. // Since setDocumentClass() causes deletion of the old document class @@ -522,6 +521,17 @@ void putClipboard(ParagraphList const & paragraphs, ErrorList el; pasteSelectionHelper(dit, paragraphs, docclass, buffer, el); + return buffer; +} + + +void putClipboard(ParagraphList const & paragraphs, + DocumentClassConstPtr docclass, docstring const & plaintext) +{ + Buffer * buffer = copyToTempBuffer(paragraphs, docclass); + if (!buffer) // already asserted in copyToTempBuffer() + return; + // We don't want to produce images that are not used. Therefore, // output formulas as MathML. Even if this is not understood by all // applications, the number that can parse it should go up in the future. @@ -1051,11 +1061,16 @@ void clearCutStack() } -docstring selection(size_t sel_index) +docstring selection(size_t sel_index, DocumentClassConstPtr docclass) { - return sel_index < theCuts.size() - ? theCuts[sel_index].first.back().asString(AS_STR_INSETS | AS_STR_NEWLINES) - : docstring(); + if (sel_index >= theCuts.size()) + return docstring(); + + boost::scoped_ptr buffer(copyToTempBuffer(theCuts[sel_index].first, docclass)); + if (!buffer) + return docstring(); + + return buffer->paragraphs().back().asString(AS_STR_INSETS | AS_STR_NEWLINES); }