]> git.lyx.org Git - features.git/commitdiff
Fix bug 5088:
authorVincent van Ravesteijn <vfr@lyx.org>
Wed, 26 Nov 2008 19:26:29 +0000 (19:26 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Wed, 26 Nov 2008 19:26:29 +0000 (19:26 +0000)
http://bugzilla.lyx.org/show_bug.cgi?id=5088

After executing DEPM to remove a double space, the position of the cursor was only 'fixed' if the cursor remained in the same par. This patch corrects this
to fix the position of the cursor also when the cursor is in a nested inset which is in the same par. This is needed because otherwise the cursor would not
point to the inset but one pos after it.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27715 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text2.cpp

index 9db9b76036ca1ddf401ec88933242fc5d83760d6..c078e38ea9e9b1572a7736bac16c711d599d7499 100644 (file)
@@ -802,10 +802,18 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
        // delete the LineSeparator.
        // MISSING
 
-       bool const same_inset = &old.inset() == &cur.inset();
-       bool const same_par = same_inset && old.pit() == cur.pit();
-       bool const same_par_pos = same_par && old.pos() == cur.pos();
+       // Find a common inset and the corresponding depth.
+       size_t depth = 0;
+       for (; depth < cur.depth(); ++depth)
+               if (&old.inset() == &cur[depth].inset())
+                       break;
 
+       // Whether a common inset is found and whether the cursor is still in 
+       // the same paragraph (possibly nested).
+       bool same_par = depth < cur.depth() && old.pit() == cur[depth].pit();
+       bool const same_par_pos = depth == cur.depth() - 1 && same_par 
+               && old.pos() == cur[depth].pos();
+       
        // If the chars around the old cursor were spaces, delete one of them.
        if (!same_par_pos) {
                // Only if the cursor has really moved.
@@ -822,7 +830,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 // automated way in CursorSlice code. (JMarc 26/09/2001)
                        // correct all cursor parts
                        if (same_par) {
-                               fixCursorAfterDelete(cur.top(), old.top());
+                               fixCursorAfterDelete(cur[depth], old.top());
                                need_anchor_change = true;
                        }
                        return true;