From ceb51f7f765c1f80ec0ffecc3facc43ca2d92ddf Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 30 Dec 2006 15:05:15 +0000 Subject: [PATCH] Sanitize the DEPM! * 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 | 24 +++++++++++++++++++++++- src/BufferView.h | 3 +++ src/lyxtext.h | 10 ++++++---- src/text2.C | 30 ++++++++++-------------------- src/undo.h | 3 +++ 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 48444b80d2..94c5712b26 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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); @@ -1252,7 +1274,7 @@ bool BufferView::mouseSetCursor(LCursor & cur) // 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(); diff --git a/src/BufferView.h b/src/BufferView.h index 8ed2d3ea4a..b57d348048 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -184,6 +184,9 @@ public: /// 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); diff --git a/src/lyxtext.h b/src/lyxtext.h index c54132f554..b1a7f71f58 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -30,11 +30,11 @@ class Buffer; class BufferParams; class BufferView; class CursorSlice; +class DocIterator; class ErrorList; -class InsetBase; -class InsetBase_code; class FuncRequest; class FuncStatus; +class InsetBase; class LColor_color; class LCursor; class LyXTextClass; @@ -349,8 +349,10 @@ public: 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 diff --git a/src/text2.C b/src/text2.C index 554088df22..5de76d10df 100644 --- a/src/text2.C +++ b/src/text2.C @@ -671,7 +671,7 @@ bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos, { 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(); - return deleteEmptyParagraphMechanism(dummy, old); + cur.bv().checkDepm(dummy, old); } bool updateNeeded = false; @@ -1207,14 +1207,14 @@ bool LyXText::cursorDown(LCursor & cur) 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; - return changed; + return 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); @@ -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 - 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 @@ -1333,7 +1328,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old) // correct all cursor parts if (same_par) { fixCursorAfterDelete(cur.top(), old.top()); - cur.resetAnchor(); + need_anchor_change = 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())); - 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()) - cur.resetAnchor(); + need_anchor_change = true; return false; } diff --git a/src/undo.h b/src/undo.h index 8ce44ce962..494cf7b6fb 100644 --- a/src/undo.h +++ b/src/undo.h @@ -29,6 +29,7 @@ namespace lyx { class BufferParams; class BufferView; +class DocIterator; class LCursor; @@ -118,6 +119,8 @@ void finishUndo(); */ /// 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); -- 2.39.2