diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 5de1a5c6f0..dca3f0687c 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -270,7 +270,7 @@ pasteSelectionHelper(LCursor & cur, ParagraphList const & parlist, pars[last_paste].makeSameLayout(pars[last_paste + 1]); mergeParagraph(buffer.params(), pars, last_paste); } else { - pars[last_paste + 1].stripLeadingSpaces(); + pars[last_paste + 1].stripLeadingSpaces(buffer.params().trackChanges); ++last_paste; } } @@ -309,7 +309,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params, (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 1]))) { pos_type const thissize = pars[pit].size(); if (doclear) - pars[pit + 1].stripLeadingSpaces(); + pars[pit + 1].stripLeadingSpaces(params.trackChanges); mergeParagraph(params, pars, pit); --endpit; if (pit == endpit) @@ -539,7 +539,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut) // sometimes necessary if (doclear) - text->paragraphs()[begpit].stripLeadingSpaces(); + text->paragraphs()[begpit].stripLeadingSpaces(bp.trackChanges); // cutSelection can invalidate the cursor so we need to set // it anew. (Lgb) diff --git a/src/paragraph.C b/src/paragraph.C index 9f5083961f..858f516dc1 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -560,19 +560,22 @@ void Paragraph::makeSameLayout(Paragraph const & par) } -int Paragraph::stripLeadingSpaces() +int Paragraph::stripLeadingSpaces(bool trackChanges) { if (isFreeSpacing()) return 0; - int i = 0; - while (!empty() && (isNewline(0) || isLineSeparator(0)) - && !isDeleted(0)) { - eraseChar(0, false); // no change tracking here - ++i; + int pos = 0; + int count = 0; + + while (pos < size() && (isNewline(pos) || isLineSeparator(pos))) { + if (eraseChar(pos, trackChanges)) + ++count; + else + ++pos; } - return i; + return count; } diff --git a/src/paragraph.h b/src/paragraph.h index fdafeb2e6f..5fb7af6216 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -346,7 +346,7 @@ public: int getPositionOfInset(InsetBase const * inset) const; /// Returns the number of line breaks and white-space stripped at the start - int stripLeadingSpaces(); + int stripLeadingSpaces(bool trackChanges); /// return true if we allow multiple spaces bool isFreeSpacing() const; diff --git a/src/text2.C b/src/text2.C index ca16466462..57f52363f7 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1231,7 +1231,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, return true; } - if (oldpar.stripLeadingSpaces()) + if (oldpar.stripLeadingSpaces(cur.buffer().params().trackChanges)) need_anchor_change = true; return false;