]> git.lyx.org Git - features.git/commitdiff
Fix bug #8159: Undo doesn't restore environment depth correctly
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 4 Jun 2012 16:02:59 +0000 (18:02 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 29 Jun 2012 13:33:02 +0000 (15:33 +0200)
(backported from master)

The idea is to record undo at the place where the document is modified:

1/ in Buffer::updateBuffer, add a recordUndo, with the caveat that a
   const_cast has to be used (because updateBuffer is const but
   modifies the document, go figure).

2/ in GuiApplication::dispatch, add an extra undo group that
   encompasses the updateBuffer call. Some other undo groups may be
   redundant now, but it is not a problem since they do not cost
   anything.

src/Buffer.cpp
src/frontends/qt4/GuiApplication.cpp
status.20x

index 4f7f4418a4f6e06e11cb4837df4e6a466a9b0cfb..6560da73432966fb9c8f33bd67dac5d7ad7ad880 100644 (file)
@@ -4239,7 +4239,17 @@ void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const
        pit_type const lastpit = parit.lastpit();
        for ( ; parit.pit() <= lastpit ; ++parit.pit()) {
                // reduce depth if necessary
-               parit->params().depth(min(parit->params().depth(), maxdepth));
+               if (parit->params().depth() > maxdepth) {
+                       /** FIXME: this function is const, but
+                        * nevertheless it modifies the buffer. To be
+                        * cleaner, one should modify the buffer in
+                        * another function, which is actually
+                        * non-const. This would however be costly in
+                        * terms of code duplication.
+                        */
+                       const_cast<Buffer *>(this)->undo().recordUndo(parit);
+                       parit->params().depth(maxdepth);
+               }
                maxdepth = parit->getMaxDepthAfter();
 
                if (utype == OutputUpdate) {
index fe6bf955267f5886a44f0e4aa44bf98102937159..cdf532c29ab35ad275b3ad0273922678686ba5bc 100644 (file)
@@ -1089,8 +1089,13 @@ static docstring makeDispatchMessage(docstring const & msg,
 
 void GuiApplication::dispatch(FuncRequest const & cmd)
 {
-       if (current_view_ && current_view_->currentBufferView())
+       Buffer * buffer = 0;
+       if (current_view_ && current_view_->currentBufferView()) {
                current_view_->currentBufferView()->cursor().saveBeforeDispatchPosXY();
+               buffer = &current_view_->currentBufferView()->buffer();
+               if (buffer)
+                       buffer->undo().beginUndoGroup();
+       }
 
        DispatchResult dr;
        // redraw the screen at the end (first of the two drawing steps).
@@ -1098,6 +1103,10 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
        dr.screenUpdate(Update::FitCursor);
        dispatch(cmd, dr);
        updateCurrentView(cmd, dr);
+
+       // the buffer may have been closed by one action
+       if (theBufferList().isLoaded(buffer))
+               buffer->undo().endUndoGroup();
 }
 
 
index def9da30550c9c57e42f3ade1ba841a38e4bdc5c..304a32972af0f8b169827fa82deb21110ff5f150 100644 (file)
@@ -65,6 +65,8 @@ What's new
 
 - Replace current selection when pasting (bug 8027).
 
+- Make sure that undo restores environment depth correctly (bug 8159).
+
 
 * DOCUMENTATION AND LOCALIZATION