]> git.lyx.org Git - lyx.git/commitdiff
Fix position of cursor when DEPM is used in change tracking mode
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 29 Jan 2019 09:55:12 +0000 (10:55 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 15 Feb 2019 10:03:17 +0000 (11:03 +0100)
When change tracking is active, it may happen that spaces are marked
as deleted instead of being removed. Therefore it is better to measure
the change of size of the paragraph to know how to offset the cursor.

Moreover, it the cursor was strictly after the start of the sequence
of spaces, we ensure that it is still the case.

This commit is _not_ a backport from master, which has diverged.

Part of bug #11412/

src/Text2.cpp

index 34fe1caecb495384d9df0426a5751eb7ae73428c..e73d1cc532aa2219747ea03fb499b23b340775c6 100644 (file)
@@ -789,7 +789,7 @@ namespace {
 // fix the cursor `cur' after characters has been deleted at `where'
 // position. Called by deleteEmptyParagraphMechanism
 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where,
-                                                 pos_type from, pos_type to)
+                          pos_type from, int num_chars)
 {
        // Do nothing if cursor is not in the paragraph where the
        // deletion occurred,
@@ -798,7 +798,7 @@ void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where,
 
        // If cursor position is after the deletion place update it
        if (cur.pos() > from)
-               cur.pos() = max(from, cur.pos() - (to - from));
+               cur.pos() = max(from + 1, cur.pos() - num_chars);
 
        // Check also if we don't want to set the cursor on a spot behind the
        // pagragraph because we erased the last character.
@@ -874,6 +874,10 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 
                // Remove spaces and adapt cursor.
                if (from < to) {
+                       // we need to remember what the size was because
+                       // eraseChars might mark spaces as deleted instead of
+                       // removing them.
+                       int const oldsize = oldpar.size();
                        oldpar.eraseChars(from, to, cur.buffer()->params().track_changes);
 // FIXME: This will not work anymore when we have multiple views of the same buffer
 // In this case, we will have to correct also the cursors held by
@@ -881,7 +885,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 // automated way in CursorSlice code. (JMarc 26/09/2001)
                        // correct all cursor parts
                        if (same_par) {
-                               fixCursorAfterDelete(cur[depth], old.top(), from, to);
+                               fixCursorAfterDelete(cur[depth], old.top(), from, oldsize - oldpar.size());
                                need_anchor_change = true;
                        }
                        return true;