From 44b0bd4eee6c103b0b7381253e88ec9057742c8d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 29 Nov 2006 13:58:08 +0000 Subject: [PATCH] Fix keyboard navigation with graphics insets. * lyxtext.h/text2.C: - LyXText::getPitNearY(): this is non const anymore. The CoordCache will be updated automatically if the paragraph is not found in there. - LyXText::checkInsetHit(): this is non const anymore because of the above. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16104 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/lyxtext.h | 11 +++++++++-- src/text2.C | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/lyxtext.h b/src/lyxtext.h index f88de27317..38b6e71c68 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -141,7 +141,14 @@ public: */ Row const & getRowNearY(BufferView const & bv, int y, pit_type pit) const; - pit_type getPitNearY(BufferView const & bv, int y) const; + + /// returns the paragraph number closest to screen y-coordinate. + /// This method uses the BufferView CoordCache to locate the + /// paragraph. The y-coodinate is allowed to be off-screen and + /// the CoordCache will be automatically updated if needed. This is + /// the reason why we need a non const BufferView and why this + /// method is non-const. + pit_type getPitNearY(BufferView & bv, int y); /** returns the column near the specified x-coordinate of the row x is set to the real beginning of this column @@ -276,7 +283,7 @@ public: int height() const; /// Returns an inset if inset was hit, or 0 if not. - InsetBase * checkInsetHit(BufferView const &, int x, int y) const; + InsetBase * checkInsetHit(BufferView &, int x, int y); /// int singleWidth(Buffer const &, Paragraph const & par, diff --git a/src/text2.C b/src/text2.C index 680fa350ee..d1399ebd91 100644 --- a/src/text2.C +++ b/src/text2.C @@ -102,7 +102,7 @@ bool LyXText::isMainText(Buffer const & buffer) const //takes screen x,y coordinates -InsetBase * LyXText::checkInsetHit(BufferView const & bv, int x, int y) const +InsetBase * LyXText::checkInsetHit(BufferView & bv, int x, int y) { pit_type pit = getPitNearY(bv, y); BOOST_ASSERT(pit != -1); @@ -904,7 +904,7 @@ pos_type LyXText::getColumnNearX(BufferView const & bv, pit_type const pit, // y is screen coordinate -pit_type LyXText::getPitNearY(BufferView const & bv, int y) const +pit_type LyXText::getPitNearY(BufferView & bv, int y) { BOOST_ASSERT(!paragraphs().empty()); BOOST_ASSERT(bv.coordCache().getParPos().find(this) != bv.coordCache().getParPos().end()); @@ -915,10 +915,45 @@ pit_type LyXText::getPitNearY(BufferView const & bv, int y) const << endl; // look for highest numbered paragraph with y coordinate less than given y + bool found = false; pit_type pit = 0; int yy = -1; CoordCache::InnerParPosCache::const_iterator it = cc.begin(); CoordCache::InnerParPosCache::const_iterator et = cc.end(); + CoordCache::InnerParPosCache::const_iterator last = et; last--; + + // If we are off-screen (before the visible part) + if (y < 0 + // and even before the first paragraph in the cache. + && y < it->second.y_ - int(pars_[it->first].ascent())) { + // and we are not at the first paragraph in the inset. + if (it->first == 0) + return 0; + // then this is the paragraph we are looking for. + pit = it->first - 1; + // rebreak it and update the CoordCache. + redoParagraph(bv, pit); + bv.coordCache().parPos()[this][pit] = + Point(0, it->second.y_ - pars_[it->first].descent()); + return pit; + } + + // If we are off-screen (after the visible part) + if (y > bv.workHeight() + // and even after the first paragraph in the cache. + && y >= last->second.y_ + int(pars_[last->first].descent())) { + pit = last->first + 1; + // and we are not at the last paragraph in the inset. + if (pit == pars_.size()) + return it->first; + // then this is the paragraph we are looking for. + // rebreak it and update the CoordCache. + redoParagraph(bv, pit); + bv.coordCache().parPos()[this][pit] = + Point(0, last->second.y_ + pars_[last->first].ascent()); + return pit; + } + for (; it != et; ++it) { lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION -- 2.39.2