From 979a4d8ecf1f80a91399938cfd12bd1ae04682ff Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Sun, 28 Mar 2004 19:13:11 +0000 Subject: [PATCH] fixes 3 c&p crashes, and a vanishing insets bug fix git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8553 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 7 +++++++ src/CutAndPaste.C | 28 ++++++++++++---------------- src/insets/ChangeLog | 6 +++++- src/insets/insettext.h | 4 +++- src/paragraph_funcs.C | 16 ++++++---------- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cda0515861..943ad1dfbb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ + +2004-03-28 Alfredo Braunstein + + * CutAndPaste.C (pasteSelection): fix 2 crashes + (eraseSelection): fix a crash + * paragraph_funcs.C: remove a warning + 2004-03-28 Angus Leeming * lfuns.h: diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index d94dc4de6e..e3063113dc 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 136c9003ea..4e3ff26253 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,4 +1,8 @@ -2004-03-27 Alfredo Braunstein + +2004-03-28 Alfredo Braunstein + + * 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. diff --git a/src/insets/insettext.h b/src/insets/insettext.h index d1bfc83281..88e7b0c305 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -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); diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index ff7d32fd01..01a404ffe0 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -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); }