From 32148586a85518d9c368e807a32a9be54146136f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 20 May 2015 12:09:12 +0200 Subject: [PATCH] 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 --- src/Cursor.cpp | 9 +-------- src/Undo.cpp | 13 +++++++++++++ src/Undo.h | 3 +++ 3 files changed, 17 insertions(+), 8 deletions(-) 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); -- 2.39.2