]> git.lyx.org Git - features.git/commitdiff
Handle properly undo groups in embedded work areas
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 13 Dec 2017 09:38:47 +0000 (10:38 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 23 Dec 2017 18:21:12 +0000 (19:21 +0100)
When a buffer is in an embedded work area (adv. find&replace), it is
not found by BufferList:::exists(), and therefore the undo group
created in GuiApplication::dispatch and in the handling of
LFUN_COMMAND_SEQUENCE will not be closed.. Crashes can ensue, as
described in Ubuntu bug:
https://bugs.launchpad.net/bugs/1737429

The solution is to introduce BufferList::isInternal and act on it.

Fixes bug #10847.

(cherry picked from commit 8b107f0490e61b4390e925f08d21661ef50d6f49)

src/BufferList.cpp
src/BufferList.h
src/Undo.cpp
src/frontends/qt4/GuiApplication.cpp

index a61b0bfd80fdd8d80229601eb96537b7b8557fa7..5e83c7b63ebe967dcad3d87f933a005ab07f9313 100644 (file)
@@ -269,7 +269,7 @@ bool BufferList::exists(FileName const & fname) const
 }
 
 
- bool BufferList::isLoaded(Buffer const * b) const
+bool BufferList::isLoaded(Buffer const * b) const
 {
        if (!b)
                return false;
@@ -279,6 +279,16 @@ bool BufferList::exists(FileName const & fname) const
 }
 
 
+bool BufferList::isInternal(Buffer const * b) const
+{
+       if (!b)
+               return false;
+       BufferStorage::const_iterator cit =
+               find(binternal.begin(), binternal.end(), b);
+       return cit != binternal.end();
+}
+
+
 bool BufferList::isOthersChild(Buffer * parent, Buffer * child)
 {
        LASSERT(parent, return false);
index 01698af4bbc7f5b12fe7ca222db39b42ee8ced43..ca55abe8c9fdd63ce9be84fb947f53a3641fa394 100644 (file)
@@ -84,6 +84,9 @@ public:
        /// returns true if the buffer is loaded
        bool isLoaded(Buffer const * b) const;
 
+       /// returns true if the buffer is known as internal buffer
+       bool isInternal(Buffer const * b) const;
+
        /// \return index of named buffer in buffer list
        int bufferNum(support::FileName const & name) const;
 
index a479728ebde2b280e519e3c09734f292f709386f..f7ee48205f91c29e6554ed9d911518425568a774 100644 (file)
@@ -562,7 +562,8 @@ void Undo::beginUndoGroup()
        if (d->group_level_ == 0) {
                // create a new group
                ++d->group_id_;
-               LYXERR(Debug::UNDO, "+++++++Creating new group " << d->group_id_);
+               LYXERR(Debug::UNDO, "+++++++ Creating new group " << d->group_id_
+                      << " for buffer " << &d->buffer_);
        }
        ++d->group_level_;
 }
@@ -586,7 +587,8 @@ void Undo::endUndoGroup()
        if (d->group_level_ == 0) {
                // real end of the group
                d->group_cur_before_ = CursorData();
-               LYXERR(Debug::UNDO, "-------End of group " << d->group_id_);
+               LYXERR(Debug::UNDO, "------- End of group " << d->group_id_
+                      << " of buffer " << &d->buffer_);
        }
 }
 
index 1e847464d826b3e6bb4a9ba0a7c58924b4194d07..97a60e9b44763ce389bf6f78dcbeadbe9372a71b 100644 (file)
@@ -1407,7 +1407,7 @@ DispatchResult const & GuiApplication::dispatch(FuncRequest const & cmd)
        updateCurrentView(cmd, dr);
 
        // the buffer may have been closed by one action
-       if (theBufferList().isLoaded(buffer))
+       if (theBufferList().isLoaded(buffer) || theBufferList().isInternal(buffer))
                buffer->undo().endUndoGroup();
 
        d->dispatch_result_ = dr;
@@ -1883,7 +1883,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dispatch(func);
                }
                // the buffer may have been closed by one action
-               if (theBufferList().isLoaded(buffer))
+               if (theBufferList().isLoaded(buffer) || theBufferList().isInternal(buffer))
                        buffer->undo().endUndoGroup();
                break;
        }