We tried hard to make sure that text pasted into ERT has the right
pseudo-language, but we forgot to reset the language of text pasted from
ERT to normal text.
The attached patch fixes that, but I am not entirely lucky with it. I would
like to explicitly handle LFUN_COPY and LFUN_PASTE in InsetERT, but this
means either to reimplement copySelection and cutSelection, or to do some
surgery to these functions. Both is not nice either, so I went with the
attached solution.
Comments?
If this is to go in: Does anybody have a better name for
resetOwnerAndChanges?
Georg
Index: src/CutAndPaste.C
===================================================================
--- src/CutAndPaste.C (Revision 13659)
+++ src/CutAndPaste.C (Arbeitskopie)
@@ -24,6 +24,7 @@
#include "funcrequest.h"
#include "gettext.h"
#include "insetiterator.h"
+#include "language.h"
#include "lfuns.h"
#include "lyxrc.h"
#include "lyxtext.h"
@@ -73,12 +74,22 @@ CutStack theCuts(10);
// when we (hopefully) have a one-for-all paste mechanism.
bool dirty_tabular_stack_;
-class resetOwnerAndChanges : public std::unary_function<Paragraph, void> {
+class resetOwnerAndChanges : public std::unary_function<Paragraph, Buffer const &> {
public:
+ resetOwnerAndChanges(Buffer const & b) : buffer_(b) {}
void operator()(Paragraph & p) const {
p.cleanChanges();
+ // ERT paragraphs have the Language latex_language.
+ // This is invalid outside of ERT, so we need to change it
+ // to the buffer language.
+ if (p.ownerCode() == InsetBase::ERT_CODE) {
+ p.changeLanguage(buffer_.params(), latex_language,
+ buffer_.getLanguage());
+ }
p.setInsetOwner(0);
}
+private:
+ Buffer const & buffer_;
};
@@ -307,7 +318,7 @@ PitPosPair eraseSelectionHelper(BufferPa
}
-void copySelectionHelper(ParagraphList & pars,
+void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
pit_type startpit, pit_type endpit,
int start, int end, textclass_type tc)
{
@@ -319,7 +330,7 @@ void copySelectionHelper(ParagraphList &
ParagraphList paragraphs(boost::next(pars.begin(), startpit),
boost::next(pars.begin(), endpit + 1));
- for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
+ for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges(buf));
// Cut out the end of the last paragraph.
Paragraph & back = paragraphs.back();
@@ -485,7 +496,8 @@ void cutSelection(LCursor & cur, bool do
BufferParams const & bp = cur.buffer().params();
if (realcut) {
- copySelectionHelper(text->paragraphs(),
+ copySelectionHelper(cur.buffer(),
+ text->paragraphs(),
begpit, endpit,
cur.selBegin().pos(), endpos,
bp.textclass);
@@ -557,7 +569,7 @@ void copySelection(LCursor & cur)
&& (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
++pos;
- copySelectionHelper(pars, par, cur.selEnd().pit(),
+ copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
pos, cur.selEnd().pos(), cur.buffer().params().textclass);
}
@@ -567,7 +579,7 @@ void copySelection(LCursor & cur)
pars.push_back(Paragraph());
BufferParams const & bp = cur.buffer().params();
pars.back().layout(bp.getLyXTextClass().defaultLayout());
- for_each(pars.begin(), pars.end(), resetOwnerAndChanges());
+ for_each(pars.begin(), pars.end(), resetOwnerAndChanges(cur.buffer()));
pars.back().insert(0, grabSelection(cur), LyXFont());
theCuts.push(make_pair(pars, bp.textclass));
}