]> git.lyx.org Git - features.git/commitdiff
change tracking:
authorMichael Schmitt <michael.schmitt@teststep.org>
Sun, 22 Oct 2006 14:36:08 +0000 (14:36 +0000)
committerMichael Schmitt <michael.schmitt@teststep.org>
Sun, 22 Oct 2006 14:36:08 +0000 (14:36 +0000)
* src/paragraph.h: rename erase() to eraseChars()
for consistency with eraseChar()
* src/paragraph_pimpl.h: dito; merge the two erase() methods
* src/*.C: adjust properly

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15478 a592a061-630c-0410-9148-cb99ea01b6c8

src/CutAndPaste.C
src/lyxfind.C
src/paragraph.C
src/paragraph.h
src/paragraph_pimpl.C
src/paragraph_pimpl.h

index 1423323e0096937737dc6571a81477ddf82fd7b1..9e0b9c17fd6803609f2775919c5a6ffe6cafa96c 100644 (file)
@@ -309,7 +309,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params,
        // Start and end is inside same paragraph
        if (endpit == pit_type(pars.size()) ||
            startpit == endpit) {
-               endpos -= pars[startpit].erase(startpos, endpos, false);
+               endpos -= pars[startpit].eraseChars(startpos, endpos, false);
                return PitPosPair(endpit, endpos);
        }
 
@@ -325,7 +325,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params,
                pos_type const right = ( pit == endpit ? endpos :
                                pars[pit].size() + 1 );
                // Logical erase only:
-               pars[pit].erase(left, right, false);
+               pars[pit].eraseChars(left, right, false);
                // Separate handling of para break:
                if (merge && pit != endpit &&
                   (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 1]))) {
@@ -363,11 +363,13 @@ void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
 
        // Cut out the end of the last paragraph.
        Paragraph & back = paragraphs.back();
-       back.erase(end, back.size(), false);
+       // do not track deletion here; it is an internal action not visible to the user
+       back.eraseChars(end, back.size(), false);
 
        // Cut out the begin of the first paragraph
        Paragraph & front = paragraphs.front();
-       front.erase(0, start, false);
+       // again, do not track deletion
+       front.eraseChars(0, start, false);
 
        theCuts.push(make_pair(paragraphs, tc));
 }
index 60892d632049e718b7d18a39fc45b4b929a9aa9f..8e547a9aaf5da339b721e1699cc8a1ac02da30fb 100644 (file)
@@ -184,7 +184,7 @@ int replaceAll(BufferView * bv,
                pos_type pos = cur.pos();
                LyXFont const font
                        = cur.paragraph().getFontSettings(buf.params(), pos);
-               int striked = ssize - cur.paragraph().erase(pos, pos + ssize,
+               int striked = ssize - cur.paragraph().eraseChars(pos, pos + ssize,
                                                            buf.params().trackChanges);
                cur.paragraph().insert(pos, from_utf8(replacestr), font,
                                       Change(buf.params().trackChanges ?
index 43a4f2722284a28f3bbad480867c224ff6110a2d..84ab0f9ffed2c528e8cf0bc2e4152868c0b216c6 100644 (file)
@@ -241,9 +241,9 @@ bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
 }
 
 
-int Paragraph::erase(pos_type start, pos_type end, bool trackChanges)
+int Paragraph::eraseChars(pos_type start, pos_type end, bool trackChanges)
 {
-       return pimpl_->erase(start, end, trackChanges);
+       return pimpl_->eraseChars(start, end, trackChanges);
 }
 
 
index 7bb6e96ea0ac71cf15f0fe606c8bcdbd185caec7..14979602b67ec668f5ddbe3b968e1556cc8db433 100644 (file)
@@ -240,10 +240,10 @@ public:
        ///
        void applyLayout(LyXLayout_ptr const & new_layout);
 
-       /// erase the char at the given position
+       /// (logically) erase the char at pos; return true if it was actually erased
        bool eraseChar(pos_type pos, bool trackChanges);
-       /// erase the given range. Returns the number of chars actually erased
-       int erase(pos_type start, pos_type end, bool trackChanges);
+       /// (logically) erase the given range; return the number of chars actually erased
+       int eraseChars(pos_type start, pos_type end, bool trackChanges);
 
        /** Get uninstantiated font setting. Returns the difference
            between the characters font and the layoutfont.
index 7e530cef8e743b144edb43d187bb1efe27edb59a..ff3bd2f2c3f2d729762577d8d5e2797fbfd83a1c 100644 (file)
@@ -151,7 +151,7 @@ void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end)
                                // Suppress access to nonexistent
                                // "end-of-paragraph char":
                                if (i < size()) {
-                                       eraseChar(i);
+                                       eraseChar(i, false);
                                        --end;
                                        --i;
                                }
@@ -181,7 +181,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
 
                        case Change::INSERTED:
                                if (i < size()) {
-                                       eraseChar(i);
+                                       eraseChar(i, false);
                                        --end;
                                        --i;
                                }
@@ -253,8 +253,29 @@ void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
 }
 
 
-void Paragraph::Pimpl::eraseChar(pos_type pos)
+bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
 {
+       BOOST_ASSERT(pos <= size());
+
+       if (trackChanges) {
+               Change::Type changetype(changes_.lookup(pos).type);
+
+               if (changetype == Change::UNCHANGED) {
+                       setChange(pos, Change(Change::DELETED));
+                       return false;
+               }
+
+               if (changetype == Change::DELETED)
+                       return false;
+       }
+
+       // Don't physically access nonexistent end-of-paragraph char
+       if (pos == size()) {
+               // FIXME: change tracking (MG)
+               // how do we handle end-of-pars previously marked inserted?
+               return false;
+       }
+
        // track change
        changes_.erase(pos);
 
@@ -297,36 +318,12 @@ void Paragraph::Pimpl::eraseChar(pos_type pos)
 
        // Update the insetlist
        owner_->insetlist.decreasePosAfterPos(pos);
-}
 
-
-bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
-{
-       BOOST_ASSERT(pos <= size());
-
-       if (trackChanges) {
-               Change::Type changetype(changes_.lookup(pos).type);
-
-               if (changetype == Change::UNCHANGED) {
-                       setChange(pos, Change(Change::DELETED));
-                       return false;
-               }
-
-               if (changetype == Change::DELETED)
-                       return false;
-       }
-
-       // Don't physically access nonexistent end-of-paragraph char
-       if (pos < size()) {
-               eraseChar(pos);
-               return true;
-       }
-
-       return false;
+       return true;
 }
 
 
-int Paragraph::Pimpl::erase(pos_type start, pos_type end, bool trackChanges)
+int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges)
 {
        pos_type i = start;
        for (pos_type count = end - start; count; --count) {
index 98d588a67c21b410cc98a14c294407843fe40916..aacf9bb3b52c868a23ace0fbec940bf6a2f8c5d4 100644 (file)
@@ -60,12 +60,10 @@ public:
        void insertChar(pos_type pos, value_type c, Change const & change);
        ///
        void insertInset(pos_type pos, InsetBase * inset, Change const & change);
-       /// definite erase
-       void eraseChar(pos_type pos);
-       /// erase the given position. Returns true if it was actually erased
+       /// (logically) erase the char at pos; return true if it was actually erased
        bool eraseChar(pos_type pos, bool trackChanges);
-       /// erase the given range
-       int erase(pos_type start, pos_type end, bool trackChanges);
+       /// (logically) erase the given range; return the number of chars actually erased
+       int eraseChars(pos_type start, pos_type end, bool trackChanges);
        ///
        InsetBase * inset_owner;