diff --git a/src/BufferView.C b/src/BufferView.C index f63a617a9f..15d63e703a 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -862,7 +862,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) #warning FIXME changes #endif while (findNextChange(this)) - getLyXText()->acceptOrRejectChange(cursor_, LyXText::ChangeOp::ACCEPT); + getLyXText()->acceptOrRejectChanges(cursor_, LyXText::ChangeOp::ACCEPT); break; } @@ -872,7 +872,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) #warning FIXME changes #endif while (findNextChange(this)) - getLyXText()->acceptOrRejectChange(cursor_, LyXText::ChangeOp::REJECT); + getLyXText()->acceptOrRejectChanges(cursor_, LyXText::ChangeOp::REJECT); break; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index d6f8f8ebb2..d2cc25c2f0 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -279,73 +279,13 @@ void InsetText::setChange(Change const & change) void InsetText::acceptChanges(BufferParams const & bparams) { - ParagraphList & pars = paragraphs(); - pit_type pars_size = (pit_type) 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 - text_.deleteEmptyParagraphMechanism(0, pars.size() - 1, bparams.trackChanges); + text_.acceptChanges(bparams); } void InsetText::rejectChanges(BufferParams const & bparams) { - ParagraphList & pars = paragraphs(); - pit_type pars_size = (pit_type) pars.size(); - - // first, reject 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].rejectChanges(bparams, 0, pars[pit].size()); - } - - // next, reject imaginary end-of-par characters - for (pit_type pit = 0; pit < pars_size; ++pit) { - pos_type pos = pars[pit].size(); - - if (pars[pit].isDeleted(pos)) { - pars[pit].setChange(pos, Change(Change::UNCHANGED)); - } else if (pars[pit].isInserted(pos)) { - if (pit == pars.size() - 1) { - // we mark the par break at the end of the last - // paragraph unchanged - pars[pit].setChange(pos, Change(Change::UNCHANGED)); - } else { - mergeParagraph(bparams, pars, pit); - --pit; - --pars_size; - } - } - } - - // finally, invoke the DEPM - text_.deleteEmptyParagraphMechanism(0, pars.size() - 1, bparams.trackChanges); + text_.rejectChanges(bparams); } diff --git a/src/lyxtext.h b/src/lyxtext.h index 55448a1a5d..ccb24ec461 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -159,7 +159,11 @@ public: REJECT }; /// accept or reject the selected change - void acceptOrRejectChange(LCursor & cur, ChangeOp op); + void acceptOrRejectChanges(LCursor & cur, ChangeOp op); + /// accept the changes within the complete LyXText + void acceptChanges(BufferParams const & bparams); + /// reject the changes within the complete LyXText + void rejectChanges(BufferParams const & bparams); /// returns true if par was empty and was removed bool setCursor(LCursor & cur, pit_type par, pos_type pos, diff --git a/src/text.C b/src/text.C index a7872c70cf..6b5d64e363 100644 --- a/src/text.C +++ b/src/text.C @@ -845,7 +845,7 @@ bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc) } -void LyXText::acceptOrRejectChange(LCursor & cur, ChangeOp op) +void LyXText::acceptOrRejectChanges(LCursor & cur, ChangeOp op) { BOOST_ASSERT(this == cur.text()); @@ -949,6 +949,76 @@ void LyXText::acceptOrRejectChange(LCursor & cur, ChangeOp op) } +void LyXText::acceptChanges(BufferParams const & bparams) +{ + pit_type pars_size = (pit_type) 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); +} + + +void LyXText::rejectChanges(BufferParams const & bparams) +{ + pit_type pars_size = (pit_type) pars_.size(); + + // first, reject 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].rejectChanges(bparams, 0, pars_[pit].size()); + } + + // next, reject imaginary end-of-par characters + for (pit_type pit = 0; pit < pars_size; ++pit) { + pos_type pos = pars_[pit].size(); + + if (pars_[pit].isDeleted(pos)) { + pars_[pit].setChange(pos, Change(Change::UNCHANGED)); + } else if (pars_[pit].isInserted(pos)) { + if (pit == pars_size - 1) { + // we mark the par break at the end of the last + // paragraph 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); +} + + // Delete from cursor up to the end of the current or next word. void LyXText::deleteWordForward(LCursor & cur) { diff --git a/src/text2.C b/src/text2.C index a447565c38..bc9980e1de 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1246,6 +1246,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, void LyXText::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges) { + BOOST_ASSERT(first >= 0 && first <= last && last < pars_.size()); + for (pit_type pit = first; pit <= last; ++pit) { Paragraph & par = pars_[pit]; diff --git a/src/text3.C b/src/text3.C index d02e4e7540..0646847ebd 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1429,12 +1429,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_CHANGE_ACCEPT: { - acceptOrRejectChange(cur, ACCEPT); + acceptOrRejectChanges(cur, ACCEPT); break; } case LFUN_CHANGE_REJECT: { - acceptOrRejectChange(cur, REJECT); + acceptOrRejectChanges(cur, REJECT); break; }