From: Michael Schmitt Date: Sun, 22 Oct 2006 14:36:08 +0000 (+0000) Subject: change tracking: X-Git-Tag: 1.6.10~12246 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0aaa8c5bcc03167509a9b25124aa839e33ff3ca0;p=features.git change tracking: * 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 --- diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 1423323e00..9e0b9c17fd 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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)); } diff --git a/src/lyxfind.C b/src/lyxfind.C index 60892d6320..8e547a9aaf 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -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 ? diff --git a/src/paragraph.C b/src/paragraph.C index 43a4f27222..84ab0f9ffe 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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); } diff --git a/src/paragraph.h b/src/paragraph.h index 7bb6e96ea0..14979602b6 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -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. diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 7e530cef8e..ff3bd2f2c3 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -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) { diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index 98d588a67c..aacf9bb3b5 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -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;