From 7bc7431b491684dada16208183fe5d96abe92a41 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Tue, 26 Jun 2007 14:11:42 +0000 Subject: [PATCH] Fix to bug 3886 acceptChanges: * move the bulk of acceptChanges without the call to DEPM to paragraph_funcs copySelectionHelper: * call this new acceptChanges pasteParagraphList: * use Text::setCursor(Cusor,...) instead of Text::setCursor(CursorSlice...) in order to have DEPM invoked at the end of the insertion git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18892 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 9 ++------- src/Text.cpp | 32 ++------------------------------ src/paragraph_funcs.cpp | 32 ++++++++++++++++++++++++++++++++ src/paragraph_funcs.h | 3 +++ 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 3f1be1e43a..869d4707fe 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -388,12 +388,7 @@ void copySelectionHelper(Buffer const & buf, ParagraphList & pars, } // do not copy text (also nested in insets) which is marked as deleted - // acceptChanges() is defined for Text rather than ParagraphList - // Thus we must wrap copy_pars into a Text object and cross our fingers - Text lt; - copy_pars.swap(lt.paragraphs()); - lt.acceptChanges(buf.params()); - copy_pars.swap(lt.paragraphs()); + acceptChanges(copy_pars, buf.params()); cutstack.push(make_pair(copy_pars, tc)); } @@ -723,7 +718,7 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist, textclass, errorList); updateLabels(cur.buffer()); cur.clearSelection(); - text->setCursor(cur.top(), ppp.first, ppp.second); + text->setCursor(cur, ppp.first, ppp.second); } // mathed is handled in InsetMathNest/InsetMathGrid diff --git a/src/Text.cpp b/src/Text.cpp index 67b50ad6e4..50311608a0 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -993,36 +993,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) void Text::acceptChanges(BufferParams const & bparams) { - pit_type pars_size = static_cast(pars_.size()); - - // first, accept changes within each individual paragraph - // (do not consider end-of-par) - for (pit_type pit = 0; pit < pars_size; ++pit) { - if (!pars_[pit].empty()) // prevent assertion failure - pars_[pit].acceptChanges(bparams, 0, pars_[pit].size()); - } - - // next, accept imaginary end-of-par characters - for (pit_type pit = 0; pit < pars_size; ++pit) { - pos_type pos = pars_[pit].size(); - - if (pars_[pit].isInserted(pos)) { - pars_[pit].setChange(pos, Change(Change::UNCHANGED)); - } else if (pars_[pit].isDeleted(pos)) { - if (pit == pars_size - 1) { - // we cannot remove a par break at the end of the last - // paragraph; instead, we mark it unchanged - pars_[pit].setChange(pos, Change(Change::UNCHANGED)); - } else { - mergeParagraph(bparams, pars_, pit); - --pit; - --pars_size; - } - } - } - - // finally, invoke the DEPM - deleteEmptyParagraphMechanism(0, pars_size - 1, bparams.trackChanges); + lyx::acceptChanges(pars_, bparams); + deleteEmptyParagraphMechanism(0, pars_.size() - 1, bparams.trackChanges); } diff --git a/src/paragraph_funcs.cpp b/src/paragraph_funcs.cpp index 66ff44d749..bc2d3257a0 100644 --- a/src/paragraph_funcs.cpp +++ b/src/paragraph_funcs.cpp @@ -317,4 +317,36 @@ int numberOfOptArgs(Paragraph const & par) } +void acceptChanges(ParagraphList & pars, BufferParams const & bparams) +{ + pit_type pars_size = static_cast(pars.size()); + + // first, accept changes within each individual paragraph + // (do not consider end-of-par) + for (pit_type pit = 0; pit < pars_size; ++pit) { + if (!pars[pit].empty()) // prevent assertion failure + pars[pit].acceptChanges(bparams, 0, pars[pit].size()); + } + + // next, accept imaginary end-of-par characters + for (pit_type pit = 0; pit < pars_size; ++pit) { + pos_type pos = pars[pit].size(); + + if (pars[pit].isInserted(pos)) { + pars[pit].setChange(pos, Change(Change::UNCHANGED)); + } else if (pars[pit].isDeleted(pos)) { + if (pit == pars_size - 1) { + // we cannot remove a par break at the end of the last + // paragraph; instead, we mark it unchanged + pars[pit].setChange(pos, Change(Change::UNCHANGED)); + } else { + mergeParagraph(bparams, pars, pit); + --pit; + --pars_size; + } + } + } +} + + } // namespace lyx diff --git a/src/paragraph_funcs.h b/src/paragraph_funcs.h index 5ae3ad5554..59786081cb 100644 --- a/src/paragraph_funcs.h +++ b/src/paragraph_funcs.h @@ -75,6 +75,9 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars); /// return the number of InsetOptArg in a paragraph int numberOfOptArgs(Paragraph const & par); +/// accept the changes within the complete ParagraphList +void acceptChanges(ParagraphList & pars, BufferParams const & bparams); + } // namespace lyx