//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);
// 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());
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 == int(pars_.size()))
+ return last->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
}
pit_type pit = getPitNearY(cur.bv(), y);
BOOST_ASSERT(pit != -1);
+ // When another window is opened with the same document, rows()
+ // will be cleared so pars_[pit].rows() might be empty when switching
+ // between windwos. A better solution is that each buffer view
+ // has its own rows() for the same buffer.
+ if (pars_[pit].rows().empty())
+ redoParagraph(cur.bv(), pit);
Row const & row = getRowNearY(cur.bv(), y, pit);
bool bound = false;
&& oldpar.isLineSeparator(old.pos() - 1)
&& !oldpar.isDeleted(old.pos() - 1)) {
oldpar.eraseChar(old.pos() - 1, false); // do not track changes in DEPM
+ // rebreak it and update the CoordCache.
+ redoParagraph(cur.bv(), old.pit());
#ifdef WITH_WARNINGS
#warning This will not work anymore when we have multiple views of the same buffer
// In this case, we will have to correct also the cursors held by