]> git.lyx.org Git - features.git/commitdiff
fix properly http://bugzilla.lyx.org/show_bug.cgi?id=2040
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 17 Sep 2008 14:51:27 +0000 (14:51 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 17 Sep 2008 14:51:27 +0000 (14:51 +0000)
* 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
src/BufferView.h
src/frontends/qt4/GuiView.cpp

index 2620dd65f730ee44aace1187eaf4a8165c609707..da3a721b48bd8b52573cd045eee15dd07cf9c40a 100644 (file)
@@ -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");
index 791e01231d6cf1d4b4af6cff6f629823c3d0c110..d41826067128c4e037a6a2cb891e863a54a095e1 100644 (file)
@@ -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.
index dbcbd163e0454eae5cb136d239fb9e783adce8c8..29c3e5843d3556d15983958e24ca6fb682a2148a 100644 (file)
@@ -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);
                        }