]> git.lyx.org Git - features.git/commitdiff
fixes 3 c&p crashes, and a vanishing insets bug fix
authorAlfredo Braunstein <abraunst@lyx.org>
Sun, 28 Mar 2004 19:13:11 +0000 (19:13 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Sun, 28 Mar 2004 19:13:11 +0000 (19:13 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8553 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/CutAndPaste.C
src/insets/ChangeLog
src/insets/insettext.h
src/paragraph_funcs.C

index cda0515861b9aae65d42b181e5ec0a4df723d994..943ad1dfbb07af21c894088045036b2ee17bdfe3 100644 (file)
@@ -1,3 +1,10 @@
+
+2004-03-28  Alfredo Braunstein  <abraunst@lyx.org>
+
+       * CutAndPaste.C (pasteSelection): fix 2 crashes
+       (eraseSelection): fix a crash
+       * paragraph_funcs.C: remove a warning
+
 2004-03-28  Angus Leeming  <leeming@lyx.org>
 
        * lfuns.h:
index d94dc4de6e463a9e92ccad29d6b2f2208dbf70f1..e3063113dcd9e5cbd549aef6429bf091ee1fea65 100644 (file)
@@ -161,19 +161,17 @@ PitPosPair eraseSelection(BufferParams const & params, ParagraphList & pars,
                all_erased = false;
 
        // Loop through the deleted pars if any, erasing as needed
-
-       par_type pit = startpit + 1;
-
-       while (pit != endpit && pit != par_type(pars.size())) {
-               par_type const next = pit + 1;
+       for (par_type pit = startpit + 1; pit != endpit;) {
                // "erase" the contents of the par
                pars[pit].erase(0, pars[pit].size());
                if (!pars[pit].size()) {
                        // remove the par if it's now empty
                        pars.erase(pars.begin() + pit);
-               } else
+                       --endpit;
+               } else {
+                       ++pit;
                        all_erased = false;
-               pit = next;
+               }
        }
 
 #if 0 // FIXME: why for cut but not copy ?
@@ -333,14 +331,10 @@ pasteSelection(Buffer const & buffer, ParagraphList & pars,
 
        // Paste it!
        pars.insert(pars.begin() + pit + 1, insertion.begin(), insertion.end());
-       par_type last_paste = pit + insertion.size();
-
-       // If we only inserted one paragraph.
-       if (insertion.size() == 1)
-               last_paste = pit;
-
        mergeParagraph(buffer.params(), pars, pit);
 
+       par_type last_paste = pit + insertion.size() - 1;
+       
        // Store the new cursor position.
        pit = last_paste;
        pos = pars[last_paste].size();
@@ -353,13 +347,15 @@ pasteSelection(Buffer const & buffer, ParagraphList & pars,
                        pars[last_paste + 1].makeSameLayout(pars[last_paste]);
                        mergeParagraph(buffer.params(), pars, last_paste);
                } else if (pars[last_paste].empty()) {
-                       pars[last_paste].makeSameLayout(pars[last_paste]);
+                       pars[last_paste].makeSameLayout(pars[last_paste + 1]);
                        mergeParagraph(buffer.params(), pars, last_paste);
-               } else
+               } else {
                        pars[last_paste + 1].stripLeadingSpaces();
+                       ++last_paste;
+               }
        }
 
-       return make_pair(PitPosPair(pit, pos), pit + insertion.size() + 1);
+       return make_pair(PitPosPair(pit, pos), last_paste + 1);
 }
 
 
index 136c9003ea4c6b595ddbd2b32475a06f9c832d67..4e3ff262531ab935af52b31b8d0ac855b7a03426 100644 (file)
@@ -1,4 +1,8 @@
-2004-03-27  Alfredo Braunstein  <abraunst@lyx.org>
+
+2004-03-28  Alfredo Braunstein  <abraunst@lyx.org>
+
+       * insettext.h: add insetAllowed returning true by default (fixing
+       vanishing insets problem)
 
        * insettext.C (draw): handle the responsability of adding the
        ouside offset to collapsable. Clean code a bit.
index d1bfc83281a5b3014fc79a007c2c7de49f397a24..88e7b0c305576736cdcfef7537089e50309d0e20 100644 (file)
@@ -142,7 +142,9 @@ public:
        size_t nargs() const { return 1; }
        ///
        ParagraphList & paragraphs() const;
-
+       ///
+       bool insetAllowed(Code) const { return true; }
+       
 protected:
        ///
        void priv_dispatch(LCursor & cur, FuncRequest & cmd);
index ff7d32fd01faeb2a17d09785a9ef20b53641ab5f..01a404ffe0d656b5811a449dc03c580f0cbf1988 100644 (file)
@@ -126,18 +126,14 @@ void breakParagraph(BufferParams const & bparams,
                // copy everything behind the break-position
                // to the new paragraph
 
-#ifdef WITH_WARNINGS
-#warning this seems wrong
-#endif
-               /* FIXME: if !keepempty, empty() == true, then we reach
-                * here with size() == 0. So pos_end becomes - 1. Why
-                * doesn't this cause problems ???
+               /* Note: if !keepempty, empty() == true, then we reach
+                * here with size() == 0. So pos_end becomes - 1. This
+                * doesn't cause problems because both loops below
+                * enforce pos <= pos_end and 0 <= pos
                 */
                pos_type pos_end = pars[par].size() - 1;
-               pos_type i = pos;
-               pos_type j = pos;
 
-               for (; i <= pos_end; ++i) {
+               for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
                        Change::Type change = pars[par].lookupChange(i);
                        if (moveItem(pars[par], *tmp, bparams, i, j - pos)) {
                                tmp->setChange(j - pos, change);
@@ -145,7 +141,7 @@ void breakParagraph(BufferParams const & bparams,
                        }
                }
 
-               for (i = pos_end; i >= pos; --i)
+               for (pos_type i = pos_end; i >= pos; --i)
                        pars[par].eraseIntern(i);
        }