X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=a30f40040714e0bfbdbe4642bea3f03b661db4d1;hb=2098f1d8c20d51e63e670bcdc9da8996068975bf;hp=91d5321325465bea0c442fd73947d7a0597f2145;hpb=408b96bb928c7fcc436f554732e20ef112b5e4b1;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 91d5321325..a30f400407 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -33,7 +33,6 @@ #include "LyXRC.h" #include "Text.h" #include "Paragraph.h" -#include "paragraph_funcs.h" #include "ParagraphParameters.h" #include "ParIterator.h" #include "Undo.h" @@ -164,7 +163,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, } } - InsetText in(buffer); + InsetText in(cur.buffer()); // Make sure there is no class difference. in.paragraphs().clear(); // This works without copying any paragraph data because we have @@ -430,10 +429,27 @@ void putClipboard(ParagraphList const & paragraphs, } -void copySelectionHelper(Buffer const & buf, ParagraphList const & pars, +/// return true if the whole ParagraphList is deleted +static bool isFullyDeleted(ParagraphList const & pars) +{ + pit_type const pars_size = static_cast(pars.size()); + + // check all paragraphs + for (pit_type pit = 0; pit < pars_size; ++pit) { + if (!pars[pit].empty()) // prevent assertion failure + if (!pars[pit].isDeleted(0, pars[pit].size())) + return false; + } + return true; +} + + +void copySelectionHelper(Buffer const & buf, Text const & text, pit_type startpit, pit_type endpit, int start, int end, DocumentClass const * const dc, CutStack & cutstack) { + ParagraphList const & pars = text.paragraphs(); + LASSERT(0 <= start && start <= pars[startpit].size(), /**/); LASSERT(0 <= end && end <= pars[endpit].size(), /**/); LASSERT(startpit != endpit || start <= end, /**/); @@ -464,7 +480,7 @@ void copySelectionHelper(Buffer const & buf, ParagraphList const & pars, // PassThru paragraphs have the Language // latex_language. This is invalid for others, so we // need to change it to the buffer language. - if (it->inInset().getLayout().isPassThru()) + if (text.inset().getLayout().isPassThru()) it->changeLanguage(buf.params(), latex_language, buf.language()); } @@ -592,7 +608,10 @@ void switchBetweenClasses(DocumentClass const * const oldone, if (it->lyxCode() != FLEX_CODE) // FIXME: Should we verify all InsetCollapsable? continue; - if (!it->undefined()) + docstring const & n = newone->insetLayout(it->name()).name(); + bool const is_undefined = n.empty() || + n == DocumentClass::plainInsetLayout().name(); + if (!is_undefined) continue; // The flex inset is undefined in newtc docstring const s = bformat(_( @@ -674,7 +693,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut) BufferParams const & bp = cur.buffer()->params(); if (realcut) { copySelectionHelper(*cur.buffer(), - text->paragraphs(), + *text, begpit, endpit, cur.selBegin().pos(), endpos, bp.documentClassPtr(), theCuts); @@ -776,7 +795,7 @@ void copySelectionToStack(Cursor const & cur, CutStack & cutstack) (par != cur.selEnd().pit() || pos < cur.selEnd().pos())) ++pos; - copySelectionHelper(*cur.buffer(), pars, par, cur.selEnd().pit(), + copySelectionHelper(*cur.buffer(), *text, par, cur.selEnd().pit(), pos, cur.selEnd().pos(), cur.buffer()->params().documentClassPtr(), cutstack); @@ -939,9 +958,9 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs) return; cur.recordUndo(); if (asParagraphs) - cur.text()->insertStringAsParagraphs(cur, text); + cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); else - cur.text()->insertStringAsLines(cur, text); + cur.text()->insertStringAsLines(cur, text, cur.current_font); } @@ -956,7 +975,7 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */, return; // create inset for graphic - InsetGraphics * inset = new InsetGraphics(*cur.buffer()); + InsetGraphics * inset = new InsetGraphics(cur.buffer()); InsetGraphicsParams params; params.filename = support::DocFileName(filename.absFilename()); inset->setParams(params); @@ -1085,7 +1104,8 @@ docstring grabSelection(Cursor const & cur) if (i1.idx() == i2.idx()) { if (i1.inset().asInsetMath()) { MathData::const_iterator it = i1.cell().begin(); - return asString(MathData(it + i1.pos(), it + i2.pos())); + Buffer * buf = cur.buffer(); + return asString(MathData(buf, it + i1.pos(), it + i2.pos())); } else { return from_ascii("unknown selection 1"); }