X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FCutAndPaste.cpp;h=988dba41542fd375439dc54f5a6d5f2b175302c8;hb=670efa8f646218f2a378f0cc614c4c37a9f6b89a;hp=0bfd3ad4e91bcfbd1657e1170e59240794f313ee;hpb=b596330093d3fa5d80e3ffc185771df77a02393b;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 0bfd3ad4e9..988dba4154 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -62,14 +62,14 @@ #include "support/lstrings.h" #include "support/lyxalgo.h" #include "support/TempFile.h" +#include "support/unique_ptr.h" #include "frontends/alert.h" #include "frontends/Clipboard.h" #include "frontends/Selection.h" -#include - #include +#include using namespace std; using namespace lyx::support; @@ -100,11 +100,11 @@ bool checkPastePossible(int index) struct PasteReturnValue { - PasteReturnValue(pit_type r_par, pos_type r_pos, bool r_nu) : - par(r_par), pos(r_pos), needupdate(r_nu) + PasteReturnValue(pit_type r_pit, pos_type r_pos, bool r_nu) : + pit(r_pit), pos(r_pos), needupdate(r_nu) {} - pit_type par; + pit_type pit; pos_type pos; bool needupdate; }; @@ -160,7 +160,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, // set the paragraphs to plain layout if necessary DocumentClassConstPtr newDocClass = buffer.params().documentClassPtr(); if (cur.inset().usePlainLayout()) { - bool forcePlainLayout = cur.inset().forcePlainLayout(); + bool forcePlainLayout = target_inset->forcePlainLayout(); Layout const & plainLayout = newDocClass->plainLayout(); Layout const & defaultLayout = newDocClass->defaultLayout(); ParagraphList::iterator const end = insertion.end(); @@ -387,7 +387,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, // Paste it! if (empty) { - pars.insert(next(pars.begin(), pit), + pars.insert(lyx::next(pars.begin(), pit), insertion.begin(), insertion.end()); @@ -395,7 +395,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, mergeParagraph(buffer.params(), pars, pit + insertion.size() - 1); } else { - pars.insert(next(pars.begin(), pit + 1), + pars.insert(lyx::next(pars.begin(), pit + 1), insertion.begin(), insertion.end()); @@ -599,8 +599,8 @@ void copySelectionHelper(Buffer const & buf, Text const & text, LASSERT(startpit != endpit || start <= end, return); // Clone the paragraphs within the selection. - ParagraphList copy_pars(next(pars.begin(), startpit), - next(pars.begin(), endpit + 1)); + ParagraphList copy_pars(lyx::next(pars.begin(), startpit), + lyx::next(pars.begin(), endpit + 1)); // Remove the end of the last paragraph; afterwards, remove the // beginning of the first paragraph. Keep this order - there may only @@ -811,22 +811,20 @@ vector availableSelections(Buffer const * buf) // we do not use cit-> here because gcc 2.9x does not // like it (JMarc) ParagraphList const & pars = (*cit).first; - docstring asciiSel; + docstring textSel; ParagraphList::const_iterator pit = pars.begin(); ParagraphList::const_iterator pend = pars.end(); for (; pit != pend; ++pit) { - Paragraph par(*pit, 0, 26); + Paragraph par(*pit, 0, 46); // adapt paragraph to current buffer. par.setBuffer(const_cast(*buf)); - asciiSel += par.asString(AS_STR_INSETS); - if (asciiSel.size() > 25) { - asciiSel.replace(22, docstring::npos, - from_ascii("...")); + textSel += par.asString(AS_STR_INSETS); + if (textSel.size() > 45) { + support::truncateWithEllipsis(textSel,45); break; } } - - selList.push_back(asciiSel); + selList.push_back(textSel); } return selList; @@ -877,11 +875,9 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut) if (begpit != endpit) cur.screenUpdateFlags(Update::Force | Update::FitCursor); - boost::tie(endpit, endpos) = - eraseSelectionHelper(bp, - text->paragraphs(), - begpit, endpit, - cur.selBegin().pos(), endpos); + tie(endpit, endpos) = + eraseSelectionHelper(bp, text->paragraphs(), begpit, endpit, + cur.selBegin().pos(), endpos); // cutSelection can invalidate the cursor so we need to set // it anew. (Lgb) @@ -963,20 +959,11 @@ void copySelectionToStack(Cursor const & cur, CutStack & cutstack) LBUFERR(text); // ok we have a selection. This is always between cur.selBegin() // and sel_end cursor - - // copy behind a space if there is one - ParagraphList & pars = text->paragraphs(); - pos_type pos = cur.selBegin().pos(); - pit_type par = cur.selBegin().pit(); - while (pos < pars[par].size() && - pars[par].isLineSeparator(pos) && - (par != cur.selEnd().pit() || pos < cur.selEnd().pos())) - ++pos; - - copySelectionHelper(*cur.buffer(), *text, par, cur.selEnd().pit(), - pos, cur.selEnd().pos(), - cur.buffer()->params().documentClassPtr(), cutstack); - + copySelectionHelper(*cur.buffer(), *text, + cur.selBegin().pit(), cur.selEnd().pit(), + cur.selBegin().pos(), cur.selEnd().pos(), + cur.buffer()->params().documentClassPtr(), + cutstack); // Reset the dirty_tabular_stack_ flag only when something // is copied to the clipboard (not to the selectionBuffer). if (&cutstack == &theCuts) @@ -1066,7 +1053,8 @@ docstring selection(size_t sel_index, DocumentClassConstPtr docclass) if (sel_index >= theCuts.size()) return docstring(); - boost::scoped_ptr buffer(copyToTempBuffer(theCuts[sel_index].first, docclass)); + unique_ptr buffer(copyToTempBuffer(theCuts[sel_index].first, + docclass)); if (!buffer) return docstring(); @@ -1085,7 +1073,7 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist, pasteSelectionHelper(cur, parlist, docclass, 0, errorList); cur.forceBufferUpdate(); cur.clearSelection(); - text->setCursor(cur, prv.par, prv.pos); + text->setCursor(cur, prv.pit, prv.pos); } // mathed is handled in InsetMathNest/InsetMathGrid @@ -1180,6 +1168,7 @@ bool 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.forceBufferUpdate(); return true; } @@ -1336,7 +1325,7 @@ void selClearOrDel(Cursor & cur) if (lyxrc.auto_region_delete) selDel(cur); else - cur.setSelection(false); + cur.selection(false); }