From 2668764493fa1d743fe37fbad2ca81fe84202e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 1 May 2003 14:45:04 +0000 Subject: [PATCH] =?UTF-8?q?2003-05-01=20=20Lars=20Gullik=20Bj=EF=BF=BDnnes?= =?UTF-8?q?=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CutAndPaste.C (pasteSelection): more clean up, user proper ParagraphList functions for pasteing. * ParagraphList.C (insert): new function, three arg insert git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6911 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 9 ++++++++ src/CutAndPaste.C | 54 +++++++++++++++++++-------------------------- src/ParagraphList.C | 9 ++++++++ src/ParagraphList.h | 2 ++ 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d931a46572..e5a4175957 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2003-05-01 Lars Gullik Bjønnes + * CutAndPaste.C (pasteSelection): more clean up, user proper + ParagraphList functions for pasteing. + + * ParagraphList.C (insert): new function, three arg insert + +2003-05-01 Lars Gullik Bjønnes + + * ParagraphList.C (insert): new function, three arg insert + * CutAndPaste.C (pasteSelection): work on the simple_cut_clone, not on paragraphs. diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index c93b5dcb72..e64e18f677 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -225,7 +225,7 @@ CutAndPaste::pasteSelection(ParagraphList & pars, // at level 0. if ((int(tmpbuf->params().depth()) + depth_delta) < 0) depth_delta = 0; - // set the right depth so that we are not too deep or shallow. + // Set the right depth so that we are not too deep or shallow. tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta); if (tmpbuf->params().depth() > max_depth) tmpbuf->params().depth(max_depth); @@ -258,12 +258,6 @@ CutAndPaste::pasteSelection(ParagraphList & pars, // the cursor paragraph. simple_cut_clone.begin()->makeSameLayout(*pit); - // Find the end of the buffer. - // FIXME: change this to end() - 1 - ParagraphList::iterator lastbuffer = simple_cut_clone.begin(); - while (boost::next(lastbuffer) != simple_cut_clone.end()) - ++lastbuffer; - bool paste_the_end = false; // Open the paragraph for inserting the buf @@ -278,42 +272,40 @@ CutAndPaste::pasteSelection(ParagraphList & pars, ParagraphList::iterator endpit = boost::next(boost::next(pit)); // Paste it! - lastbuffer->next(pit->next()); - pit->next()->previous(&*lastbuffer); - pit->next(&*simple_cut_clone.begin()); - simple_cut_clone.begin()->previous(&*pit); + ParagraphList::iterator past_pit = boost::next(pit); + // It is possible that std::list::splice also could be used here. + pars.insert(past_pit, + simple_cut_clone.begin(), simple_cut_clone.end()); + ParagraphList::iterator last_paste = boost::prior(past_pit); - if (boost::next(pit) == lastbuffer) - lastbuffer = pit; + // If we only inserted one paragraph. + if (boost::next(pit) == last_paste) + last_paste = pit; mergeParagraph(current_view->buffer()->params, pars, pit); // Store the new cursor position. - pit = lastbuffer; - pos = lastbuffer->size(); + pit = last_paste; + pos = last_paste->size(); + // Maybe some pasting. - if (boost::next(lastbuffer) != simple_cut_clone.end() && paste_the_end) { - if (boost::next(lastbuffer)->hasSameLayout(*lastbuffer)) { + if (boost::next(last_paste) != simple_cut_clone.end() && + paste_the_end) { + if (boost::next(last_paste)->hasSameLayout(*last_paste)) { mergeParagraph(current_view->buffer()->params, pars, - lastbuffer); - } else if (!boost::next(lastbuffer)->size()) { - boost::next(lastbuffer)->makeSameLayout(*lastbuffer); + last_paste); + } else if (boost::next(last_paste)->empty()) { + boost::next(last_paste)->makeSameLayout(*last_paste); mergeParagraph(current_view->buffer()->params, pars, - lastbuffer); - } else if (!lastbuffer->size()) { - lastbuffer->makeSameLayout(*boost::next(lastbuffer)); + last_paste); + } else if (last_paste->empty()) { + last_paste->makeSameLayout(*boost::next(last_paste)); mergeParagraph(current_view->buffer()->params, pars, - lastbuffer); + last_paste); } else - boost::next(lastbuffer)->stripLeadingSpaces(); + boost::next(last_paste)->stripLeadingSpaces(); } -#if 1 - // For the time beeing we must do this to avoid deleting the - // newly pasted paragraphs. - simple_cut_clone.set(0); -#endif - return make_pair(PitPosPair(pit, pos), endpit); } diff --git a/src/ParagraphList.C b/src/ParagraphList.C index 3a579413e1..d9c66152d4 100644 --- a/src/ParagraphList.C +++ b/src/ParagraphList.C @@ -158,6 +158,15 @@ ParagraphList::insert(ParagraphList::iterator it, Paragraph * par) } + +void ParagraphList::insert(iterator pos, iterator beg, iterator end) +{ + for (; beg != end; ++beg) { + insert(pos, new Paragraph(*beg, false)); + } +} + + void ParagraphList::assign(iterator beg, iterator end) { clear(); diff --git a/src/ParagraphList.h b/src/ParagraphList.h index 52154c1156..f64b88cd79 100644 --- a/src/ParagraphList.h +++ b/src/ParagraphList.h @@ -53,6 +53,8 @@ public: /// iterator insert(iterator it, Paragraph * par); /// + void insert(iterator pos, iterator beg, iterator end); + /// void assign(iterator beg, iterator end); /// void clear();