From: André Pönitz Date: Mon, 10 Nov 2003 18:15:55 +0000 (+0000) Subject: Alfredo's patch. X-Git-Tag: 1.6.10~15806 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6789af0a3284fa865f7b682f803bb08e2ddeae8c;p=lyx.git Alfredo's patch. Enough for today... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8073 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 8fd5b93286..c99eb53632 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -605,8 +605,11 @@ void BufferView::Pimpl::update() bv_->getLyXText()->redoCursor(); // update all 'visible' paragraphs - ParagraphList::iterator beg, end; - getVisiblePars(beg, end); + ParagraphList::iterator beg; + ParagraphList::iterator end; + getParsInRange(buffer_->paragraphs(), + top_y(), top_y() + workarea().workHeight(), + beg, end); bv_->text->redoParagraphs(beg, end); updateScrollbar(); @@ -968,7 +971,8 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) lyxerr << "cursor is: " << bv_->cursor() << endl; lyxerr << "dispatching " << cmd1 << " to surrounding LyXText " << bv_->cursor().innerText() << endl; - bv_->cursor().innerText()->dispatch(cmd1); + theTempCursor.innerText()->dispatch(cmd1); + cursor_ = theTempCursor; //return DispatchResult(true, true); } @@ -979,7 +983,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) // FIXME: we should skip these when selecting owner_->updateLayoutChoice(); owner_->updateToolbar(); - fitCursor(); +// fitCursor(); // slight hack: this is only called currently when we // clicked somewhere, so we force through the display @@ -1341,20 +1345,3 @@ void BufferView::Pimpl::updateParagraphDialog() } -void BufferView::Pimpl::getVisiblePars - (ParagraphList::iterator & beg, ParagraphList::iterator & end) -{ - beg = bv_->text->cursorPar(); - end = beg; - - for ( ; beg != bv_->text->ownerParagraphs().begin(); --beg) - if (beg->y - top_y() < 0) - break; - - if (beg != bv_->text->ownerParagraphs().begin()) - --beg; - - for ( ; end != bv_->text->ownerParagraphs().end(); ++end) - if (end->y - top_y() > workarea().workHeight()) - break; -} diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index a7f06bce88..776888c2d9 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -193,8 +193,6 @@ private: void MenuInsertLyXFile(std::string const & filen); /// our workarea WorkArea & workarea() const; - /// range of visible main text paragraphs - void getVisiblePars(ParagraphList::iterator &, ParagraphList::iterator &); /// LCursor cursor_; diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 491dde8781..6504f4fc90 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -61,7 +61,6 @@ std::string const currentState(BufferView *); void replaceSelection(LyXText * lt); - }; // namespace bv_funcs #endif diff --git a/src/lyxtext.h b/src/lyxtext.h index a860240359..af7f6bcfb5 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -343,9 +343,8 @@ public: void updateCounters(); /** * Returns an inset if inset was hit, or 0 if not. - * If hit, the coordinates are changed relative to the inset. */ - InsetOld * checkInsetHit(int & x, int & y); + InsetOld * checkInsetHit(int x, int y); /// int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const; diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index ec55e8bea6..884b6933dc 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -610,3 +610,24 @@ Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset) BOOST_ASSERT(false); return buf.paragraphs().front(); // shut up compiler } + + + + +void getParsInRange(ParagraphList & pl, + int ystart, int yend, + ParagraphList::iterator & beg, + ParagraphList::iterator & end) +{ + ParagraphList::iterator const endpar = pl.end(); + ParagraphList::iterator const begpar = pl.begin(); + + BOOST_ASSERT(begpar != endpar); + + beg = endpar; + for (--beg; beg != begpar && beg->y > ystart; --beg) + ; + + for (end = beg ; end != endpar && end->y < yend; ++end) + ; +} diff --git a/src/paragraph_funcs.h b/src/paragraph_funcs.h index dc282599e1..22be6f6668 100644 --- a/src/paragraph_funcs.h +++ b/src/paragraph_funcs.h @@ -75,5 +75,12 @@ ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset); /// find owning paragraph containing an inset Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset); +/// stretch range beg,end to the minimum containing ystart, yend +void getParsInRange(ParagraphList & pl, + int ystart, int yend, + ParagraphList::iterator & beg, + ParagraphList::iterator & end); + + #endif // PARAGRAPH_FUNCS_H diff --git a/src/text2.C b/src/text2.C index fe8c5ddd9d..725bca209c 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1624,11 +1624,10 @@ void LyXText::cursorUp(bool selecting) if (!selecting) { int topy = bv()->top_y(); int y1 = cursor.y() - topy; - int y2 = y1; y -= topy; InsetOld * inset_hit = checkInsetHit(x, y1); if (inset_hit && isHighlyEditableInset(inset_hit)) - inset_hit->edit(bv(), x, y - (y2 - y1)); + inset_hit->edit(bv(), x, y); } #else lyxerr << "cursorUp: y " << cursor.y() << " bl: " << @@ -1650,11 +1649,10 @@ void LyXText::cursorDown(bool selecting) if (!selecting) { int topy = bv()->top_y(); int y1 = cursor.y() - topy; - int y2 = y1; y -= topy; InsetOld * inset_hit = checkInsetHit(x, y1); if (inset_hit && isHighlyEditableInset(inset_hit)) - inset_hit->edit(bv(), x, y - (y2 - y1)); + inset_hit->edit(bv(), x, y); } #else setCursorFromCoordinates(bv()->x_target(), diff --git a/src/text3.C b/src/text3.C index 09eecd3e14..a82a92dda5 100644 --- a/src/text3.C +++ b/src/text3.C @@ -31,6 +31,7 @@ #include "lyxrc.h" #include "lyxrow.h" #include "paragraph.h" +#include "paragraph_funcs.h" #include "ParagraphParameters.h" #include "text_funcs.h" #include "undo.h" @@ -256,11 +257,15 @@ string const freefont2string() -InsetOld * LyXText::checkInsetHit(int & x, int & y) +InsetOld * LyXText::checkInsetHit(int x, int y) { - ParagraphList::iterator pit = ownerParagraphs().begin(); - ParagraphList::iterator end = ownerParagraphs().end(); + ParagraphList::iterator pit; + ParagraphList::iterator end; + getParsInRange(ownerParagraphs(), + bv()->top_y(), bv()->top_y() + bv()->workHeight(), + pit, end); + lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl; for ( ; pit != end; ++pit) { InsetList::iterator iit = pit->insetlist.begin(); @@ -279,7 +284,6 @@ InsetOld * LyXText::checkInsetHit(int & x, int & y) && y <= inset->y() + inset->descent()) { lyxerr << "Hit inset: " << inset << endl; - y += bv()->top_y(); return inset; } }