From: Jean-Marc Lasgouttes Date: Wed, 20 May 2015 10:09:12 +0000 (+0200) Subject: Place the cursor correctly after undoing an inset dissolution X-Git-Tag: 2.2.0alpha1~720 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=32148586a85518d9c368e807a32a9be54146136f;hp=a911b1cc658e5e8de90b1fa267f7c7385a95f4c0;p=features.git Place the cursor correctly after undoing an inset dissolution The cleanup in 11ca1406 was not correct. It is actually not possible to implement recordUndoInset from the undo API, since the cursor may not be at a different level than the text to be saved. Fixes ticket #9553 --- diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 17ee74e9c1..44457e335f 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -2496,14 +2496,7 @@ void Cursor::recordUndo(UndoKind kind) const void Cursor::recordUndoInset(Inset const * in) const { - if (!in || in == &inset()) { - CursorData c = *this; - c.pop_back(); - buffer()->undo().recordUndo(c, c.pit(), c.pit()); - } else if (in == nextInset()) - recordUndo(); - else - LYXERR0("Inset not found, no undo element added."); + buffer()->undo().recordUndoInset(*this, in); } diff --git a/src/Undo.cpp b/src/Undo.cpp index 95eb160d60..1ab11d3774 100644 --- a/src/Undo.cpp +++ b/src/Undo.cpp @@ -587,6 +587,19 @@ void Undo::recordUndo(CursorData const & cur, pit_type from, pit_type to) } +void Undo::recordUndoInset(CursorData const & cur, Inset const * inset) +{ + if (!inset || inset == &cur.inset()) { + DocIterator c = cur; + c.pop_back(); + d->recordUndo(ATOMIC_UNDO, c, c.pit(), c.pit(), cur); + } else if (inset == cur.nextInset()) + recordUndo(cur); + else + LYXERR0("Inset not found, no undo stack added."); +} + + void Undo::recordUndoBufferParams(CursorData const & cur) { d->recordUndoBufferParams(cur); diff --git a/src/Undo.h b/src/Undo.h index 789de5f39f..95514ab0b2 100644 --- a/src/Undo.h +++ b/src/Undo.h @@ -102,6 +102,9 @@ public: /// paragraph or cell containing the cursor. void recordUndo(CursorData const & cur, UndoKind kind = ATOMIC_UNDO); + /// prepare undo for the inset containing the cursor + void recordUndoInset(CursorData const & cur, Inset const * inset); + /// Convenience: record undo for buffer parameters void recordUndoBufferParams(CursorData const & cur);