This replaces findText with BOOST_ASSERTs and even survives File->New.

Btw, is there a nicer way to write


+       if (this != bv()->cursor().text()) {
+               lyxerr << "cursor: " << bv()->cursor()
+                       << "\ntext: " << bv()->cursor().text() 
+                       << "\nthis: " << this << endl;
+               BOOST_ASSERT(false);
+       }

Something like

+       BOOST_ASSERT(this != bv()->cursor().text())
+               << "cursor: " << bv()->cursor()
+               << "\ntext: " << bv()->cursor().text() 
+               << "\nthis: " << this << endl;

or similar?

It seems to be a macro already, so why is it not "nice"?

Andre'
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.494
diff -u -p -r1.494 BufferView_pimpl.C
--- BufferView_pimpl.C  2 Feb 2004 11:07:48 -0000       1.494
+++ BufferView_pimpl.C  2 Feb 2004 12:55:14 -0000
@@ -905,7 +902,7 @@ bool BufferView::Pimpl::workAreaDispatch
                if (inset) {
                        res = inset->dispatch(cur, cmd);
                } else {
-                       res = cur.innerText()->dispatch(cur, cmd);
+                       res = bv_->text()->dispatch(cur, cmd);
                }
 
                if (bv_->fitCursor() || res.update()) {
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.41
diff -u -p -r1.41 cursor.C
--- cursor.C    30 Jan 2004 11:40:57 -0000      1.41
+++ cursor.C    2 Feb 2004 12:55:14 -0000
@@ -474,6 +474,12 @@ void LCursor::clearTargetX()
 }
 
 
+LyXText * LCursor::text() const
+{
+       return current_ ? current().text() : bv_->text();
+}
+
+
 Paragraph & LCursor::paragraph()
 {
        return current_ ? current().paragraph() : *bv_->text()->getPar(par());
@@ -723,7 +729,7 @@ std::ostream & operator<<(std::ostream &
        os << "\n";
        for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
                os << "  (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
-       return os;
+       return os << "current: " << cur.current_ << endl;
 }
 
 
@@ -1705,7 +1711,7 @@ CursorSlice LCursor::normalAnchor()
        }
        //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
        // use Anchor on the same level as Cursor
-       CursorSlice normal = anchor_[depth() - 1];
+       CursorSlice normal = anchor_[current_];
 #if 0
        if (depth() < anchor_.size() && !(normal < xx())) {
                // anchor is behind cursor -> move anchor behind the inset
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.24
diff -u -p -r1.24 cursor.h
--- cursor.h    30 Jan 2004 11:40:57 -0000      1.24
+++ cursor.h    2 Feb 2004 12:55:14 -0000
@@ -201,6 +201,8 @@ public:
        ///
        Paragraph const & paragraph() const;
        ///
+       LyXText * text() const;
+       ///
        InsetBase * innerInsetOfType(int code) const;
        ///
        InsetTabular * innerInsetTabular() const;
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.284
diff -u -p -r1.284 lyxtext.h
--- lyxtext.h   30 Jan 2004 11:40:59 -0000      1.284
+++ lyxtext.h   2 Feb 2004 12:55:14 -0000
@@ -391,10 +391,6 @@ public:
        CursorSlice & cursor();
        /// the topmost cursor slice
        CursorSlice const & cursor() const;
-       /// access to the selection anchor
-       CursorSlice & anchor();
-       /// access to the selection anchor
-       CursorSlice const & anchor() const;
 
        friend class LyXScreen;
 
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.111
diff -u -p -r1.111 rowpainter.C
--- rowpainter.C        30 Jan 2004 11:40:59 -0000      1.111
+++ rowpainter.C        2 Feb 2004 12:55:14 -0000
@@ -136,8 +136,9 @@ RowPainter::RowPainter(BufferView const 
                paintBackground();
 
        // paint the selection background
-       if (bv_.cursor().selection() && &text_ == bv_.cursor().innerText())
-               paintSelection();
+#warning look here for selection
+       //if (bv_.cursor().selection() && &text_ == bv_.cursor().innerText())
+       //      paintSelection();
 
        // vertical lines for appendix
        paintAppendix();
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.528
diff -u -p -r1.528 text.C
--- text.C      31 Jan 2004 15:30:21 -0000      1.528
+++ text.C      2 Feb 2004 12:55:14 -0000
@@ -1933,46 +1933,26 @@ int LyXText::cursorY(CursorSlice const &
 }
 
 
-namespace {
-
-int findText(LyXText const * text)
-{
-       CursorBase & cur = text->bv()->cursor().cursor_;
-       //lyxerr << "findText: text: " << text << " cursor: "
-       //      << text->bv()->cursor() << endl;
-       for (int i = cur.size() - 1; i > 0; --i)
-               if (cur[i].text() == text)
-                       return i;
-       if (text->bv()->text() == text)
-               return 0;
-       lyxerr << "Trying to access text not touched by cursor" << endl;
-       BOOST_ASSERT(false);
-       return 0; // shut up compiler
-}
-
-}
-
-
 CursorSlice & LyXText::cursor()
 {
        //lyxerr << "# accessing slice " << findText(this) << endl;
-       return bv()->cursor().cursor_[findText(this)];
+       if (this != bv()->cursor().text()) {
+               lyxerr << "cursor: " << bv()->cursor()
+                       << "\ntext: " << bv()->cursor().text() 
+                       << "\nthis: " << this << endl;
+               BOOST_ASSERT(false);
+       }
+       return bv()->cursor().current();
 }
 
 
 CursorSlice const & LyXText::cursor() const
 {
-       return bv()->cursor().cursor_[findText(this)];
-}
-
-
-CursorSlice & LyXText::anchor()
-{
-       return bv()->cursor().anchor_[findText(this)];
-}
-
-
-CursorSlice const & LyXText::anchor() const
-{
-       return bv()->cursor().anchor_[findText(this)];
+       if (this != bv()->cursor().text()) {
+               lyxerr << "cursor: " << bv()->cursor()
+                       << "\ntext: " << bv()->cursor().text() 
+                       << "\nthis: " << this << endl;
+               BOOST_ASSERT(false);
+       }
+       return bv()->cursor().current();
 }

Reply via email to