From a73da74db27a840eb30862352585281d8cfaa3ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 2 Feb 2004 16:38:13 +0000 Subject: [PATCH] * cursor.[Ch]: remove direct access to anchor * text.C: remove findText() hack git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8382 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 5 +---- src/ChangeLog | 6 ++++++ src/cursor.C | 10 +++++++-- src/cursor.h | 2 ++ src/lyxtext.h | 4 ---- src/rowpainter.C | 5 +++-- src/text.C | 48 ++++++++++++------------------------------ src/text2.C | 7 +++--- src/text3.C | 12 ++++++----- 9 files changed, 44 insertions(+), 55 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a71644d47b..8b8b009896 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -328,9 +328,6 @@ void BufferView::Pimpl::buffer(Buffer * b) if (bv_->text() == 0) resizeCurrentBuffer(); - // FIXME: needed when ? - fitCursor(); - // Buffer-dependent dialogs should be updated or // hidden. This should go here because some dialogs (eg ToC) // require bv_->text. @@ -905,7 +902,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) 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()) { diff --git a/src/ChangeLog b/src/ChangeLog index 83653aae7b..c1f42914d6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,10 @@ +2004-02-02 André Pönitz + + * cursor.[Ch]: remove direct access to anchor + + * text.C: remove findText() hack + 2004-02-02 Alfredo Braunstein * iterators.[Ch] (lockPath): remove in favour of... diff --git a/src/cursor.C b/src/cursor.C index 7c43f3092f..955d308424 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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, LCursor const & cur) 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 diff --git a/src/cursor.h b/src/cursor.h index f7a119fd15..68c257c793 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -201,6 +201,8 @@ public: /// Paragraph const & paragraph() const; /// + LyXText * text() const; + /// InsetBase * innerInsetOfType(int code) const; /// InsetTabular * innerInsetTabular() const; diff --git a/src/lyxtext.h b/src/lyxtext.h index 61a8cbbdc4..4a29e3022d 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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; diff --git a/src/rowpainter.C b/src/rowpainter.C index 7772d889f2..1bebde2723 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -136,8 +136,9 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text, 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(); diff --git a/src/text.C b/src/text.C index 82cd90bb99..78874de8a2 100644 --- a/src/text.C +++ b/src/text.C @@ -1933,46 +1933,26 @@ int LyXText::cursorY(CursorSlice const & cur) 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(); } diff --git a/src/text2.C b/src/text2.C index 3aa14065e6..8e0afeab87 100644 --- a/src/text2.C +++ b/src/text2.C @@ -79,9 +79,9 @@ LyXText::LyXText(BufferView * bv, bool in_inset) {} -void LyXText::init(BufferView * bview) +void LyXText::init(BufferView * bv) { - bv_owner = bview; + bv_owner = bv; ParagraphList::iterator const beg = paragraphs().begin(); ParagraphList::iterator const end = paragraphs().end(); @@ -94,8 +94,7 @@ void LyXText::init(BufferView * bview) current_font = getFont(beg, 0); redoParagraphs(beg, end); - setCursorIntern(0, 0); - bv()->cursor().resetAnchor(); + bv->cursor().resetAnchor(); updateCounters(); } diff --git a/src/text3.C b/src/text3.C index c9461f4648..ccd48cb57b 100644 --- a/src/text3.C +++ b/src/text3.C @@ -762,9 +762,10 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_BACKSPACE_SKIP: // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP. if (!cur.selection()) { - CursorSlice cur = cursor(); +#warning look here + //CursorSlice cur = cursor(); backspace(); - anchor() = cur; + //anchor() = cur; } else { cutSelection(true, false); } @@ -793,10 +794,11 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) // When at the beginning of a paragraph, remove // indentation and add a "defskip" at the top. // Otherwise, do the same as LFUN_BREAKPARAGRAPH. - CursorSlice cur = cursor(); +#warning look here +// CursorSlice cur = cursor(); replaceSelection(bv->getLyXText()); if (cur.pos() == 0) { - ParagraphParameters & params = getPar(cur)->params(); + ParagraphParameters & params = getPar(cur.current())->params(); setParagraph( params.spacing(), params.align(), @@ -805,7 +807,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) breakParagraph(bv->buffer()->paragraphs(), 0); } bv->update(); - anchor() = cur; +// anchor() = cur; bv->switchKeyMap(); bv->owner()->view_state_changed(); break; -- 2.39.2