]> git.lyx.org Git - features.git/commitdiff
2003-05-01 Lars Gullik Bj�nnes <larsbj@gullik.net>
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 1 May 2003 14:45:04 +0000 (14:45 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 1 May 2003 14:45:04 +0000 (14:45 +0000)
* 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
src/CutAndPaste.C
src/ParagraphList.C
src/ParagraphList.h

index d931a465728f809ce8251c2745cfb8ba378d422a..e5a4175957c073204a4e0aafb9a11a759fc99485 100644 (file)
@@ -1,5 +1,14 @@
 2003-05-01  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
+       * 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  <larsbj@gullik.net>
+
+       * ParagraphList.C (insert): new function, three arg insert
+
        * CutAndPaste.C (pasteSelection): work on the simple_cut_clone,
        not on paragraphs.
 
index c93b5dcb72a9b3a70d8513514091644a6abcaab6..e64e18f677ffaedf48a3061145ea1e6669d1d231 100644 (file)
@@ -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);
 }
 
index 3a579413e1c0259d4b5282e24102cafcc91ef2df..d9c66152d4e0df10cb9fb260d5483bd278cbe398 100644 (file)
@@ -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();
index 52154c115648660789644491f4d6d69f0557711b..f64b88cd79a79303ec60e857be88cac724f4fa67 100644 (file)
@@ -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();