From d585528d50e7222951b8399cd15bf0db3f8f8605 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 17 Sep 2008 14:51:27 +0000 Subject: [PATCH] fix properly http://bugzilla.lyx.org/show_bug.cgi?id=2040 * BufferView.cpp (setCursorFromInset): new method, useful to find an inset that is known to be in the document. * frontends/qt4/GuiView.cpp (dispatch): do a proper recordUndo befire appplying changes to an inset. The insets are responsible for recording additional undo steps that could be needed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26428 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 21 +++++++++++++++++++++ src/BufferView.h | 3 +++ src/frontends/qt4/GuiView.cpp | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 2620dd65f7..da3a721b48 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1742,6 +1742,27 @@ void BufferView::setCursorFromRow(int row) } +bool BufferView::setCursorFromInset(Inset const * inset) +{ + // are we already there? + if (cursor().nextInset() == inset) + return true; + + // Inset is not at cursor position. Find it in the document. + Cursor cur(*this); + cur.reset(buffer().inset()); + do + cur.forwardInset(); + while (cur && cur.nextInset() != inset); + + if (cur) { + setCursor(cur); + return true; + } + return false; +} + + void BufferView::gotoLabel(docstring const & label) { Toc & toc = buffer().tocBackend().toc("label"); diff --git a/src/BufferView.h b/src/BufferView.h index 791e01231d..d418260671 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -144,6 +144,9 @@ public: /// set the cursor based on the given TeX source row. void setCursorFromRow(int row); + /// set cursor to the given inset. Return true if found. + bool setCursorFromInset(Inset const *); + /// Ensure that the BufferView cursor is visible. /// This method will automatically scroll and update the BufferView /// if needed. diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index dbcbd163e0..29c3e5843d 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1960,13 +1960,18 @@ bool GuiView::dispatch(FuncRequest const & cmd) } case LFUN_INSET_APPLY: { - view()->cursor().recordUndoFullDocument(); string const name = cmd.getArg(0); Inset * inset = getOpenInset(name); if (inset) { + // put cursor in front of inset. + if (!view()->setCursorFromInset(inset)) + LASSERT(false, /**/); + + view()->cursor().recordUndo(); FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument()); inset->dispatch(view()->cursor(), fr); } else { + view()->cursor().recordUndo(); FuncRequest fr(LFUN_INSET_INSERT, cmd.argument()); lyx::dispatch(fr); } -- 2.39.5