mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Fix pasting insets into math (bug #9302)
The problem was that the conversion to plain text (which is used as an intermediate step) requires for some insets a valid buffer pointer, but insets in the cut stack do not have one. Now we use the same temp buffer business as for copying to the external clipboard.
This commit is contained in:
parent
19f3f630bc
commit
c5782ff4bb
@ -480,8 +480,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void putClipboard(ParagraphList const & paragraphs,
|
Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPtr docclass)
|
||||||
DocumentClassConstPtr docclass, docstring const & plaintext)
|
|
||||||
{
|
{
|
||||||
// This used to need to be static to avoid a memory leak. It no longer needs
|
// 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
|
// 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
|
// Use a clone for the complicated stuff so that we do not need to clean
|
||||||
// up in order to avoid a crash.
|
// up in order to avoid a crash.
|
||||||
Buffer * buffer = staticbuffer->cloneBufferOnly();
|
Buffer * buffer = staticbuffer->cloneBufferOnly();
|
||||||
LASSERT(buffer, return);
|
LASSERT(buffer, return 0);
|
||||||
|
|
||||||
// This needs doing every time.
|
// This needs doing every time.
|
||||||
// Since setDocumentClass() causes deletion of the old document class
|
// Since setDocumentClass() causes deletion of the old document class
|
||||||
@ -522,6 +521,17 @@ void putClipboard(ParagraphList const & paragraphs,
|
|||||||
ErrorList el;
|
ErrorList el;
|
||||||
pasteSelectionHelper(dit, paragraphs, docclass, buffer, 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,
|
// We don't want to produce images that are not used. Therefore,
|
||||||
// output formulas as MathML. Even if this is not understood by all
|
// 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.
|
// 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()
|
if (sel_index >= theCuts.size())
|
||||||
? theCuts[sel_index].first.back().asString(AS_STR_INSETS | AS_STR_NEWLINES)
|
return docstring();
|
||||||
: docstring();
|
|
||||||
|
boost::scoped_ptr<Buffer> buffer(copyToTempBuffer(theCuts[sel_index].first, docclass));
|
||||||
|
if (!buffer)
|
||||||
|
return docstring();
|
||||||
|
|
||||||
|
return buffer->paragraphs().back().asString(AS_STR_INSETS | AS_STR_NEWLINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ std::vector<docstring> availableSelections(Buffer const *);
|
|||||||
/// Get the number of available elements in the cut buffer.
|
/// Get the number of available elements in the cut buffer.
|
||||||
size_type numberOfSelections();
|
size_type numberOfSelections();
|
||||||
/// Get the sel_index-th element of the cut buffer in plain text format.
|
/// Get the sel_index-th element of the cut buffer in plain text format.
|
||||||
docstring selection(size_t sel_index);
|
docstring selection(size_t sel_index, DocumentClassConstPtr docclass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace using the font of the first selected character and select
|
* Replace using the font of the first selected character and select
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "MetricsInfo.h"
|
#include "MetricsInfo.h"
|
||||||
|
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "BufferParams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "CutAndPaste.h"
|
#include "CutAndPaste.h"
|
||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
@ -1339,7 +1340,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
idocstringstream is(cmd.argument());
|
idocstringstream is(cmd.argument());
|
||||||
int n = 0;
|
int n = 0;
|
||||||
is >> n;
|
is >> n;
|
||||||
topaste = cap::selection(n);
|
topaste = cap::selection(n, buffer().params().documentClassPtr());
|
||||||
}
|
}
|
||||||
InsetMathGrid grid(buffer_, 1, 1);
|
InsetMathGrid grid(buffer_, 1, 1);
|
||||||
if (!topaste.empty())
|
if (!topaste.empty())
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#include "Bidi.h"
|
#include "Bidi.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "BufferParams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "CoordCache.h"
|
#include "CoordCache.h"
|
||||||
#include "Cursor.h"
|
#include "Cursor.h"
|
||||||
@ -583,7 +584,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
idocstringstream is(cmd.argument());
|
idocstringstream is(cmd.argument());
|
||||||
is >> n;
|
is >> n;
|
||||||
topaste = cap::selection(n);
|
topaste = cap::selection(n, buffer().params().documentClassPtr());
|
||||||
}
|
}
|
||||||
cur.niceInsert(topaste, parseflg, false);
|
cur.niceInsert(topaste, parseflg, false);
|
||||||
cur.clearSelection(); // bug 393
|
cur.clearSelection(); // bug 393
|
||||||
|
Loading…
Reference in New Issue
Block a user