X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=4914afb7cd16e1da36586022fd17b8c06df90245;hb=8ea66efe16ad109a5c107716185fb82bbebca8c8;hp=2bac66f8a6db2d2fe4d72f078fe13c20f6b10bbd;hpb=cd2e50a27503f6845e413fb3551f53eb9803b2c4;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 2bac66f8a6..4914afb7cd 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -56,6 +56,7 @@ #include "support/debug.h" #include "support/docstream.h" #include "support/gettext.h" +#include "support/lassert.h" #include "support/limited_stack.h" #include "support/lstrings.h" @@ -227,7 +228,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist, InsetIterator const i_end = inset_iterator_end(in); for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) { // Even though this will also be done later, it has to be done here - // since, e.g., InsetLabel::updateCommand() is going to try to access + // since some inset might going to try to access // the buffer() member. it->setBuffer(const_cast(buffer)); switch (it->lyxCode()) { @@ -241,7 +242,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist, continue; InsetLabel * lab = labels[i]; docstring const oldname = lab->getParam("name"); - lab->updateCommand(oldname, false); + lab->updateLabel(oldname); // We need to update the buffer reference cache. cur.forceBufferUpdate(); docstring const newname = lab->getParam("name"); @@ -255,13 +256,13 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist, if (ref->getParam("reference") == oldname) ref->setParam("reference", newname); } else if (itt->lyxCode() == MATH_REF_CODE) { - InsetMathHull * mi = itt->asInsetMath()->asHullInset(); + InsetMathRef * mi = itt->asInsetMath()->asRefInset(); // this is necessary to prevent an uninitialized // buffer when the RefInset is in a MathBox. // FIXME audit setBuffer calls mi->setBuffer(const_cast(buffer)); - if (mi->asRefInset()->getTarget() == oldname) - mi->asRefInset()->changeTarget(newname); + if (mi->getTarget() == oldname) + mi->changeTarget(newname); } } } @@ -272,7 +273,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist, // check for duplicates InsetLabel & lab = static_cast(*it); docstring const oldname = lab.getParam("name"); - lab.updateCommand(oldname, false); + lab.updateLabel(oldname); // We need to update the buffer reference cache. cur.forceBufferUpdate(); docstring const newname = lab.getParam("name"); @@ -285,14 +286,13 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist, if (ref.getParam("reference") == oldname) ref.setParam("reference", newname); } else if (itt->lyxCode() == MATH_REF_CODE) { - InsetMathHull & mi = - static_cast(*itt); + InsetMathRef * mi = itt->asInsetMath()->asRefInset(); // this is necessary to prevent an uninitialized // buffer when the RefInset is in a MathBox. // FIXME audit setBuffer calls - mi.setBuffer(const_cast(buffer)); - if (mi.asRefInset()->getTarget() == oldname) - mi.asRefInset()->changeTarget(newname); + mi->setBuffer(const_cast(buffer)); + if (mi->getTarget() == oldname) + mi->changeTarget(newname); } } break; @@ -1044,6 +1044,40 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs) cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); else cur.text()->insertStringAsLines(cur, text, cur.current_font); + cur.setSelection(); +} + + +void pasteSimpleText(Cursor & cur, bool asParagraphs) +{ + docstring text; + // Use internal clipboard if it is the most recent one + if (theClipboard().isInternal()) { + if (!checkPastePossible(0)) + return; + + ParagraphList const & pars = theCuts[0].first; + ParagraphList::const_iterator it = pars.begin(); + for (; it != pars.end(); ++it) { + if (it != pars.begin()) + text += "\n"; + text += (*it).asString(); + } + asParagraphs = false; + } else { + // Then try plain text + text = theClipboard().getAsText(); + } + + if (text.empty()) + return; + + cur.recordUndo(); + cutSelection(cur, true, false); + if (asParagraphs) + cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); + else + cur.text()->insertStringAsLines(cur, text, cur.current_font); } @@ -1077,7 +1111,7 @@ void pasteSelection(Cursor & cur, ErrorList & errorList) } -void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwards) +void replaceSelectionWithString(Cursor & cur, docstring const & str) { cur.recordUndo(); DocIterator selbeg = cur.selectionBegin(); @@ -1096,13 +1130,6 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwa // Cut the selection cutSelection(cur, true, false); - - // select the replacement - if (backwards) { - selbeg.pos() += str.length(); - cur.setSelection(selbeg, -int(str.length())); - } else - cur.setSelection(selbeg, str.length()); }