From f29d236e84b34a0ad5b3c696fb46ba053fe76310 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Sat, 21 Oct 2006 15:36:04 +0000 Subject: [PATCH] change tracking: * src/changes.C: fix erase() and insert() git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15453 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/changes.C | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/changes.C b/src/changes.C index b92f15cb63..66ca308ce9 100644 --- a/src/changes.C +++ b/src/changes.C @@ -160,31 +160,51 @@ void Changes::set(Change const & change, pos_type const start, pos_type const en void Changes::erase(pos_type const pos) { + if (lyxerr.debugging(Debug::CHANGES)) { + lyxerr[Debug::CHANGES] << "Erasing change at position " << pos << endl; + } + ChangeTable::iterator it = table_.begin(); ChangeTable::iterator end = table_.end(); - bool found = false; - for (; it != end; ++it) { - Range & range(it->range); - - if (lyxerr.debugging(Debug::CHANGES)) { - lyxerr[Debug::CHANGES] << "era:Range of type " << it->change.type << " is " - << it->range.start << "," << it->range.end << endl; + // range (pos,pos+x) becomes (pos,pos+x-1) + if (it->range.start > pos) { + --(it->range.start); + } + // range (pos-x,pos) stays (pos-x,pos) + if (it->range.end > pos) { + --(it->range.end); } + } - if (range.contains(pos)) { - found = true; - --range.end; - continue; + merge(); +} + + +void Changes::insert(Change const & change, lyx::pos_type pos) +{ + if (lyxerr.debugging(Debug::CHANGES)) { + lyxerr[Debug::CHANGES] << "Inserting change of type " << change.type + << " at position " << pos << endl; + } + + ChangeTable::iterator it = table_.begin(); + ChangeTable::iterator end = table_.end(); + + for (; it != end; ++it) { + // range (pos,pos+x) becomes (pos+1,pos+x+1) + if (it->range.start >= pos) { + ++(it->range.start); } - if (found) { - --range.start; - --range.end; + // range (pos-x,pos) stays as it is + if (it->range.end > pos) { + ++(it->range.end); } } - merge(); + + set(change, pos, pos + 1); // set will call merge } -- 2.39.2