]> git.lyx.org Git - features.git/commitdiff
Fixup bf7f4d71: Let changeRefsIfUnique handle undo
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 12 Jan 2020 21:18:36 +0000 (22:18 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 12 Jan 2020 21:18:36 +0000 (22:18 +0100)
This allows for a much lower memory consumption than a plain
recordUnfoFullBuffer.

Related to bug 6494.

src/Buffer.cpp
src/Buffer.h
src/insets/InsetBibitem.cpp

index bd3d63e1c470c644888cb0e29bb67f91c6551cee..ffdd9b8f67b86c83d3f8b1d28457327ba976de6f 100644 (file)
@@ -4039,14 +4039,17 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to)
                return;
 
        string const paramName = "key";
                return;
 
        string const paramName = "key";
+       UndoGroupHelper ugh(this);
        InsetIterator it = inset_iterator_begin(inset());
        for (; it; ++it) {
                if (it->lyxCode() != CITE_CODE)
                        continue;
                InsetCommand * inset = it->asInsetCommand();
                docstring const oldValue = inset->getParam(paramName);
        InsetIterator it = inset_iterator_begin(inset());
        for (; it; ++it) {
                if (it->lyxCode() != CITE_CODE)
                        continue;
                InsetCommand * inset = it->asInsetCommand();
                docstring const oldValue = inset->getParam(paramName);
-               if (oldValue == from)
+               if (oldValue == from) {
+                       undo().recordUndo(CursorData(it));
                        inset->setParam(paramName, to);
                        inset->setParam(paramName, to);
+               }
        }
 }
 
        }
 }
 
index 0e1ec6b6e6441eff6df8d2cba7a47483d30f2ef1..04e9d6051878298042139f67ddbcca30079b59a2 100644 (file)
@@ -624,7 +624,7 @@ public:
        mutable UserMacroSet usermacros;
 
        /// Replace the inset contents for insets which InsetCode is equal
        mutable UserMacroSet usermacros;
 
        /// Replace the inset contents for insets which InsetCode is equal
-       /// to the passed \p inset_code.
+       /// to the passed \p inset_code. Handles undo.
        void changeRefsIfUnique(docstring const & from, docstring const & to);
 
        /// get source code (latex/docbook) for some paragraphs, or all paragraphs
        void changeRefsIfUnique(docstring const & from, docstring const & to);
 
        /// get source code (latex/docbook) for some paragraphs, or all paragraphs
index 424755b533d089515c8a227d1d564202c16a73ba..1c1962c0e635c45246d2c0b9c336c04c2b6226d8 100644 (file)
@@ -155,7 +155,7 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
                setParam("literal", p["literal"]);
 
                if (p["key"] != old_key) {
                setParam("literal", p["literal"]);
 
                if (p["key"] != old_key) {
-                       cur.recordUndoFullBuffer();
+                       // changeRefsIfUnique handles undo
                        cur.bv().buffer().changeRefsIfUnique(old_key, p["key"]);
                        updateCommand(p["key"]);
                        cur.forceBufferUpdate();
                        cur.bv().buffer().changeRefsIfUnique(old_key, p["key"]);
                        updateCommand(p["key"]);
                        cur.forceBufferUpdate();