// 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);
}
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]))) {
// 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));
}
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 ?
}
-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);
}
///
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.
// Suppress access to nonexistent
// "end-of-paragraph char":
if (i < size()) {
- eraseChar(i);
+ eraseChar(i, false);
--end;
--i;
}
case Change::INSERTED:
if (i < size()) {
- eraseChar(i);
+ eraseChar(i, false);
--end;
--i;
}
}
-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);
// 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) {
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;