]> git.lyx.org Git - lyx.git/commitdiff
change tracking:
authorMichael Schmitt <michael.schmitt@teststep.org>
Sat, 21 Oct 2006 15:36:04 +0000 (15:36 +0000)
committerMichael Schmitt <michael.schmitt@teststep.org>
Sat, 21 Oct 2006 15:36:04 +0000 (15:36 +0000)
* 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

index b92f15cb635f6e548353f6d5e3214456eb8ce96e..66ca308ce990c633f70c9dc1e351d252d2157ff1 100644 (file)
@@ -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
 }