From d53d4a5c3528c8dfa06ec55229eacac8f5783150 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Tue, 24 Oct 2006 21:38:47 +0000 Subject: [PATCH] change tracking: * src/*.C: * src/insets/*.C: implement rejectChanges() in analogy to acceptChanges(); * src/paragraph_pimpl.C: add assertions for pos, start, and end parameters git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15542 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/insetbase.h | 2 ++ src/insets/insettabular.C | 7 +++++ src/insets/insettabular.h | 2 ++ src/insets/insettext.C | 12 ++++++++ src/insets/insettext.h | 2 ++ src/paragraph.C | 4 +-- src/paragraph.h | 4 +-- src/paragraph_pimpl.C | 61 +++++++++++++++++++++++---------------- src/paragraph_pimpl.h | 4 +-- src/text.C | 2 +- 10 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index eef82e0259..55524e17c7 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -402,6 +402,8 @@ public: virtual void setChange(Change const &) {} /// accept the changes within the inset virtual void acceptChanges() {}; + /// reject the changes within the inset + virtual void rejectChanges() {}; /// pretty arbitrary virtual int width() const { return 10; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index c6f82d3a4c..18ad857530 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1921,6 +1921,13 @@ void InsetTabular::acceptChanges() } +void InsetTabular::rejectChanges() +{ + for (idx_type idx = 0; idx < nargs(); ++idx) + cell(idx)->rejectChanges(); +} + + bool InsetTabular::forceDefaultParagraphs(idx_type cell) const { return tabular.getPWidth(cell).zero(); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 469e3d27e4..a43e22e0bd 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -119,6 +119,8 @@ public: void setChange(Change const & change); /// accept the changes within the inset void acceptChanges(); + /// reject the changes within the inset + void rejectChanges(); // this should return true if we have a "normal" cell, otherwise false. // "normal" means without width set! diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 39fe2606a0..96c7dcdf8e 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -284,6 +284,18 @@ void InsetText::acceptChanges() } +void InsetText::rejectChanges() +{ + ParagraphList::iterator pit = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); + for (; pit != end; ++pit) { + // FIXME: change tracking (MG) + // we must handle end-of-par chars! + pit->rejectChanges(0, pit->size() + 1); + } +} + + int InsetText::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 34219d0bf6..0b33eb23eb 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -106,6 +106,8 @@ public: void setChange(Change const & change); /// accept the changes within the inset void acceptChanges(); + /// reject the changes within the inset + void rejectChanges(); /// append text onto the existing text void appendParagraphs(Buffer * bp, ParagraphList &); diff --git a/src/paragraph.C b/src/paragraph.C index 6f9701139c..4c9cf29828 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1447,9 +1447,9 @@ void Paragraph::acceptChanges(pos_type start, pos_type end) } -void Paragraph::rejectChange(pos_type start, pos_type end) +void Paragraph::rejectChanges(pos_type start, pos_type end) { - return pimpl_->rejectChange(start, end); + return pimpl_->rejectChanges(start, end); } diff --git a/src/paragraph.h b/src/paragraph.h index 60dd0fba93..77635bf2a3 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -220,8 +220,8 @@ public: /// accept changes within the given range void acceptChanges(pos_type start, pos_type end); - /// reject change - void rejectChange(pos_type start, pos_type end); + /// reject changes within the given range + void rejectChanges(pos_type start, pos_type end); /// Paragraphs can contain "manual labels", for example, Description /// environment. The text for this user-editable label is stored in diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 1d9512a328..df802cec42 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -89,6 +89,9 @@ void Paragraph::Pimpl::setContentsFromPar(Paragraph const & par) bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const { + BOOST_ASSERT(start >= 0 && start <= size()); + BOOST_ASSERT(end > start && end <= size() + 1); + return changes_.isChanged(start, end); } @@ -111,6 +114,8 @@ void Paragraph::Pimpl::setChange(Change const & change) void Paragraph::Pimpl::setChange(pos_type pos, Change const & change) { + BOOST_ASSERT(pos >= 0 && pos <= size()); + changes_.set(change, pos); // FIXME: change tracking (MG) @@ -123,12 +128,17 @@ void Paragraph::Pimpl::setChange(pos_type pos, Change const & change) Change const Paragraph::Pimpl::lookupChange(pos_type pos) const { + BOOST_ASSERT(pos >= 0 && pos <= size()); + return changes_.lookup(pos); } void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end) { + BOOST_ASSERT(start >= 0 && start <= size()); + BOOST_ASSERT(end > start && end <= size() + 1); + for (pos_type pos = start; pos < end; ++pos) { switch (lookupChange(pos).type) { case Change::UNCHANGED: @@ -139,8 +149,8 @@ void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end) break; case Change::DELETED: - // Suppress access to nonexistent - // "end-of-paragraph char": + // Suppress access to non-existent + // "end-of-paragraph char" if (pos < size()) { eraseChar(pos, false); --end; @@ -157,52 +167,50 @@ void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end) } -void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end) +void Paragraph::Pimpl::rejectChanges(pos_type start, pos_type end) { - // FIXME: change tracking (MG) - return; - - // care for empty pars + BOOST_ASSERT(start >= 0 && start <= size()); + BOOST_ASSERT(end > start && end <= size() + 1); - pos_type i = start; - - for (; i < end; ++i) { - switch (lookupChange(i).type) { + for (pos_type pos = start; pos < end; ++pos) { + switch (lookupChange(pos).type) { case Change::UNCHANGED: break; case Change::INSERTED: - if (i < size()) { - eraseChar(i, false); + // Suppress access to non-existent + // "end-of-paragraph char" + if (pos < size()) { + eraseChar(pos, false); --end; - --i; + --pos; } break; case Change::DELETED: - // FIXME: change tracking (MG) - changes_.set(Change(Change::UNCHANGED), i); - // No real char at position size(): - if (i < size() && owner_->isInset(i)) - // FIXME: change tracking (MG) - owner_->getInset(i)->setChange(Change(Change::UNCHANGED)); + changes_.set(Change(Change::UNCHANGED), pos); break; } + + // also reject changes in nested insets + if (pos < size() && owner_->isInset(pos)) { + owner_->getInset(pos)->rejectChanges(); + } } - // FIXME: change tracking (MG) - // changes_.reset(Change::UNCHANGED); } Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const { + BOOST_ASSERT(pos >= 0 && pos <= size()); + return owner_->getChar(pos); } void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & change) { - BOOST_ASSERT(pos <= size()); + BOOST_ASSERT(pos >= 0 && pos <= size()); // track change changes_.insert(change, pos); @@ -235,7 +243,7 @@ void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset, Change const & change) { BOOST_ASSERT(inset); - BOOST_ASSERT(pos <= size()); + BOOST_ASSERT(pos >= 0 && pos <= size()); insertChar(pos, META_INSET, change); BOOST_ASSERT(owner_->text_[pos] == META_INSET); @@ -247,7 +255,7 @@ void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset, bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges) { - BOOST_ASSERT(pos <= size()); + BOOST_ASSERT(pos >= 0 && pos <= size()); if (trackChanges) { Change::Type changetype(changes_.lookup(pos).type); @@ -317,6 +325,9 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges) int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges) { + BOOST_ASSERT(start >= 0 && start <= size()); + BOOST_ASSERT(end > start && end <= size() + 1); + pos_type i = start; for (pos_type count = end - start; count; --count) { if (!eraseChar(i, trackChanges)) diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index facbcb22fc..221fb94143 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -51,8 +51,8 @@ public: void setChange(pos_type pos, Change const & change); /// accept changes within the given range void acceptChanges(pos_type start, pos_type end); - /// reject change - void rejectChange(pos_type start, pos_type end); + /// reject changes within the given range + void rejectChanges(pos_type start, pos_type end); /// value_type getChar(pos_type pos) const; diff --git a/src/text.C b/src/text.C index d953f955d3..8ab02dfa35 100644 --- a/src/text.C +++ b/src/text.C @@ -1501,7 +1501,7 @@ void LyXText::rejectChange(LCursor & cur) pos_type left = ( pit == it.pit() ? it.pos() : 0 ); pos_type right = ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 ); - pars_[pit].rejectChange(left, right); + pars_[pit].rejectChanges(left, right); } if (isInserted) { ParagraphList & plist = paragraphs(); -- 2.39.2