]> git.lyx.org Git - lyx.git/commitdiff
Fix keyboard navigation with graphics insets.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 29 Nov 2006 13:58:08 +0000 (13:58 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 29 Nov 2006 13:58:08 +0000 (13:58 +0000)
* 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
src/text2.C

index f88de27317d80a6c7e28bc5821dd8ace37aaef36..38b6e71c68324175304cd179b9ad6aecc9e8ccd1 100644 (file)
@@ -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,
index 680fa350ee1d6cac1d376a85a795768ff508d93d..d1399ebd911c7315863efe61fed764b2c05462c3 100644 (file)
@@ -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