Consider selection scope when DEPM after CT acceptance/rejection (#2166)

This fixes a crash and DEPM overshooting.
This commit is contained in:
Juergen Spitzmueller 2021-03-02 09:15:33 +01:00
parent d49c4abb43
commit e2f3dd5f6a
3 changed files with 21 additions and 3 deletions

View File

@ -1496,7 +1496,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
}
// finally, invoke the DEPM
deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer()->params().track_changes);
deleteEmptyParagraphMechanism(begPit, endPit, begPos, endPos,
cur.buffer()->params().track_changes);
cur.finishUndo();
cur.clearSelection();

View File

@ -310,6 +310,13 @@ public:
/// Does NOT handle undo (responsibility of the caller)
void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
/// delete double spaces, leading spaces, and empty paragraphs
/// from \first to \last paragraph and \first_pos to \last_pos
/// Does NOT handle undo (responsibility of the caller)
void deleteEmptyParagraphMechanism(pit_type first, pit_type last,
pos_type first_pos, pos_type last_pos,
bool trackChanges);
/// To resolve macros properly the texts get their DocIterator.
/// Every macro definition is stored with its DocIterator
/// as well. Only those macros with a smaller iterator become

View File

@ -933,6 +933,15 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges)
{
pos_type last_pos = static_cast<pos_type>(pars_[last].size() - 1);
deleteEmptyParagraphMechanism(first, last, 0, last_pos, trackChanges);
}
void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last,
pos_type first_pos, pos_type last_pos,
bool trackChanges)
{
LASSERT(first >= 0 && first <= last && last < (int) pars_.size(), return);
@ -943,8 +952,9 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool tra
* (1) Delete consecutive spaces
*/
if (!par.isFreeSpacing()) {
pos_type from = 0;
while (from < par.size()) {
pos_type from = (pit == first) ? first_pos : 0;
pos_type to_pos = (pit == last) ? last_pos + 1 : par.size();
while (from < to_pos) {
// skip non-spaces
while (from < par.size()
&& (!par.isLineSeparator(from) || par.isDeleted(from)))