]> git.lyx.org Git - lyx.git/commitdiff
Sanitize the DEPM!
authorAbdelrazak Younes <younes@lyx.org>
Sat, 30 Dec 2006 15:05:15 +0000 (15:05 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 30 Dec 2006 15:05:15 +0000 (15:05 +0000)
* BufferView:
  - checkDepm(): new method for DEPM mechanism.
  - mouseSetCursor(): use checkDepm().

* text2.C:
  - use BufferView::checkDepm() instead of using LyXText::deleteEmptyParagraphMechanism() directly.
  - deleteEmptyParagraphMechanism(): prepare for conversion to DocIterator (code transferred to BufferView::checkDepm()).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16442 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/BufferView.h
src/lyxtext.h
src/text2.C
src/undo.h

index 48444b80d2027e39c9774111a5677ecf31390538..94c5712b26128a6c7c1a48841c75eefbdad8c71b 100644 (file)
@@ -1239,6 +1239,28 @@ void BufferView::setCursor(DocIterator const & dit)
 }
 
 
 }
 
 
+bool BufferView::checkDepm(LCursor & cur, LCursor & old)
+{
+       // Would be wrong to delete anything if we have a selection.
+       if (cur.selection())
+               return false;
+
+       bool need_anchor_change = false;
+       bool changed = cursor_.text()->deleteEmptyParagraphMechanism(cur, old,
+               need_anchor_change);
+
+       if (need_anchor_change)
+               cur.resetAnchor();
+       
+       if (!changed)
+               return false;
+
+       updateMetrics(false);
+       buffer_->changed();
+       return true;
+}
+
+
 bool BufferView::mouseSetCursor(LCursor & cur)
 {
        BOOST_ASSERT(&cur.bv() == this);
 bool BufferView::mouseSetCursor(LCursor & cur)
 {
        BOOST_ASSERT(&cur.bv() == this);
@@ -1252,7 +1274,7 @@ bool BufferView::mouseSetCursor(LCursor & cur)
        // FIXME: move this to InsetText::notifyCursorLeaves?
        bool update = false;
        if (!badcursor && cursor_.inTexted())
        // FIXME: move this to InsetText::notifyCursorLeaves?
        bool update = false;
        if (!badcursor && cursor_.inTexted())
-               update = cursor_.text()->deleteEmptyParagraphMechanism(cur, cursor_);
+               checkDepm(cur, cursor_);
 
        cursor_ = cur;
        cursor_.clearSelection();
 
        cursor_ = cur;
        cursor_.clearSelection();
index 8ed2d3ea4a38cb71c0ce9fcd988572844c3e9cbe..b57d348048c2b33b87837a671d95369507584c14 100644 (file)
@@ -184,6 +184,9 @@ public:
        /// sets cursor.
        /// This will also open all relevant collapsable insets.
        void setCursor(DocIterator const &);
        /// sets cursor.
        /// This will also open all relevant collapsable insets.
        void setCursor(DocIterator const &);
+       /// Check deleteEmptyParagraphMechanism and update metrics if needed.
+       /// \retval true if an update was needed.
+       bool checkDepm(LCursor & cur, LCursor & old);
        /// sets cursor.
        /// This is used when handling LFUN_MOUSE_PRESS.
        bool mouseSetCursor(LCursor & cur);
        /// sets cursor.
        /// This is used when handling LFUN_MOUSE_PRESS.
        bool mouseSetCursor(LCursor & cur);
index c54132f5543e06bef142afcd56690f2562d25ea0..b1a7f71f5890897a218b31d0bb6e0aa4f5c6566e 100644 (file)
@@ -30,11 +30,11 @@ class Buffer;
 class BufferParams;
 class BufferView;
 class CursorSlice;
 class BufferParams;
 class BufferView;
 class CursorSlice;
+class DocIterator;
 class ErrorList;
 class ErrorList;
-class InsetBase;
-class InsetBase_code;
 class FuncRequest;
 class FuncStatus;
 class FuncRequest;
 class FuncStatus;
+class InsetBase;
 class LColor_color;
 class LCursor;
 class LyXTextClass;
 class LColor_color;
 class LCursor;
 class LyXTextClass;
@@ -349,8 +349,10 @@ public:
                bool boundary) const;
 
        /// delete double space or empty paragraphs around old cursor
                bool boundary) const;
 
        /// delete double space or empty paragraphs around old cursor
-       /// FIXME: replace LCursor with DocIterator.
-       bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
+       /// FIXME: replace LCursor with DocIterator. This is not possible right
+       /// now because recordUndo() is called which needs a LCursor.
+       bool deleteEmptyParagraphMechanism(LCursor & cur,
+               LCursor & old, bool & need_anchor_change);
 
        /// sets row.end to the pos value *after* which a row should break.
        /// for example, the pos after which isNewLine(pos) == true
 
        /// sets row.end to the pos value *after* which a row should break.
        /// for example, the pos after which isNewLine(pos) == true
index 554088df22e90ad9053d98e9b69979b6459d5e38..5de76d10df533e98f8079780622d7c07a8b35565 100644 (file)
@@ -671,7 +671,7 @@ bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos,
 {
        LCursor old = cur;
        setCursorIntern(cur, par, pos, setfont, boundary);
 {
        LCursor old = cur;
        setCursorIntern(cur, par, pos, setfont, boundary);
-       return deleteEmptyParagraphMechanism(cur, old);
+       return cur.bv().checkDepm(cur, old);
 }
 
 
 }
 
 
@@ -1154,7 +1154,7 @@ bool LyXText::cursorUp(LCursor & cur)
                if (dummy == old)
                        ++dummy.pos();
 
                if (dummy == old)
                        ++dummy.pos();
 
-               return deleteEmptyParagraphMechanism(dummy, old);
+               cur.bv().checkDepm(dummy, old);
        }
 
        bool updateNeeded = false;
        }
 
        bool updateNeeded = false;
@@ -1207,14 +1207,14 @@ bool LyXText::cursorDown(LCursor & cur)
                LCursor dummy = cur;
                if (dummy == old)
                        ++dummy.pos();
                LCursor dummy = cur;
                if (dummy == old)
                        ++dummy.pos();
-
-               bool const changed = deleteEmptyParagraphMechanism(dummy, old);
+               
+               bool const changed = cur.bv().checkDepm(dummy, old);
 
                // Make sure that cur gets back whatever happened to dummy(Lgb)
                if (changed)
                        cur = dummy;
 
 
                // Make sure that cur gets back whatever happened to dummy(Lgb)
                if (changed)
                        cur = dummy;
 
-               return changed;
+               return false;
        }
 
        bool updateNeeded = false;
        }
 
        bool updateNeeded = false;
@@ -1276,12 +1276,9 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
 }
 
 
 }
 
 
-bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
+bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur,
+               LCursor & old, bool & need_anchor_change)
 {
 {
-       // Would be wrong to delete anything if we have a selection.
-       if (cur.selection())
-               return false;
-
        //lyxerr[Debug::DEBUG] << "DEPM: cur:\n" << cur << "old:\n" << old << endl;
        // old should point to us
        BOOST_ASSERT(old.text() == this);
        //lyxerr[Debug::DEBUG] << "DEPM: cur:\n" << cur << "old:\n" << old << endl;
        // old should point to us
        BOOST_ASSERT(old.text() == this);
@@ -1322,8 +1319,6 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
                    && oldpar.isLineSeparator(old.pos() - 1)
                    && !oldpar.isDeleted(old.pos() - 1)) {
                        oldpar.eraseChar(old.pos() - 1, false); // do not track changes in DEPM
                    && oldpar.isLineSeparator(old.pos() - 1)
                    && !oldpar.isDeleted(old.pos() - 1)) {
                        oldpar.eraseChar(old.pos() - 1, false); // do not track changes in DEPM
-                       TextMetrics & tm = cur.bv().textMetrics(this);
-                       tm.redoParagraph(old.pit());
 #ifdef WITH_WARNINGS
 #warning This will not work anymore when we have multiple views of the same buffer
 // In this case, we will have to correct also the cursors held by
 #ifdef WITH_WARNINGS
 #warning This will not work anymore when we have multiple views of the same buffer
 // In this case, we will have to correct also the cursors held by
@@ -1333,7 +1328,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
                        // correct all cursor parts
                        if (same_par) {
                                fixCursorAfterDelete(cur.top(), old.top());
                        // correct all cursor parts
                        if (same_par) {
                                fixCursorAfterDelete(cur.top(), old.top());
-                               cur.resetAnchor();
+                               need_anchor_change = true;
                        }
                        return true;
                }
                        }
                        return true;
                }
@@ -1370,19 +1365,14 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
                                // their address has changed. Therefore we
                                // need to `regenerate' cur. (JMarc)
                                cur.updateInsets(&(cur.bottom().inset()));
                                // their address has changed. Therefore we
                                // need to `regenerate' cur. (JMarc)
                                cur.updateInsets(&(cur.bottom().inset()));
-                               cur.resetAnchor();
+                               need_anchor_change = true;
                        }
                }
                        }
                }
-               // There is a crash reported by Edwin Leuven (16/04/2006) because of:
-               //ParIterator par_it(old);
-               //updateLabels(old.buffer(), par_it);
-               // So for now we do the full update:
-               updateLabels(old.buffer());
                return true;
        }
 
        if (oldpar.stripLeadingSpaces())
                return true;
        }
 
        if (oldpar.stripLeadingSpaces())
-               cur.resetAnchor();
+               need_anchor_change = true;
 
        return false;
 }
 
        return false;
 }
index 8ce44ce962da5eed385e37b57a40d6b4d0177390..494cf7b6fb70c056edaa1a3a2b08f935aaed314c 100644 (file)
@@ -29,6 +29,7 @@ namespace lyx {
 
 class BufferParams;
 class BufferView;
 
 class BufferParams;
 class BufferView;
+class DocIterator;
 class LCursor;
 
 
 class LCursor;
 
 
@@ -118,6 +119,8 @@ void finishUndo();
  */
 
 /// The general case: prepare undo for an arbitrary range.
  */
 
 /// The general case: prepare undo for an arbitrary range.
+/// FIXME: replace LCursor with DocIterator. This is not possible right
+/// now because we need access to Buffer->params()!.
 void recordUndo(LCursor & cur, Undo::undo_kind kind,
        pit_type from, pit_type to);
 
 void recordUndo(LCursor & cur, Undo::undo_kind kind,
        pit_type from, pit_type to);