* TextMetrics::getPitNearY(): Fix crash when navigating with up and down arrow keys. The problem was that the passed y coordinates was not necessarily out of screen. Also the paragraph position was not correctly updated.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21798 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-11-26 15:29:54 +00:00
parent 1133419a59
commit de8ce17784

View File

@ -1226,7 +1226,7 @@ pit_type TextMetrics::getPitNearY(int y)
<< ": y: " << y << " cache size: " << par_metrics_.size()); << ": y: " << y << " cache size: " << par_metrics_.size());
// look for highest numbered paragraph with y coordinate less than given y // look for highest numbered paragraph with y coordinate less than given y
pit_type pit = 0; pit_type pit = -1;
int yy = -1; int yy = -1;
ParMetricsCache::const_iterator it = par_metrics_.begin(); ParMetricsCache::const_iterator it = par_metrics_.begin();
ParMetricsCache::const_iterator et = par_metrics_.end(); ParMetricsCache::const_iterator et = par_metrics_.end();
@ -1234,35 +1234,31 @@ pit_type TextMetrics::getPitNearY(int y)
ParagraphMetrics const & pm = it->second; ParagraphMetrics const & pm = it->second;
// If we are off-screen (before the visible part) if (y < it->second.position() - int(pm.ascent())) {
if (y < 0 // We are looking for a position that is before the first paragraph in
// and even before the first paragraph in the cache. // the cache (which is in priciple off-screen, that is before the
&& y < it->second.position() - int(pm.ascent())) { // visible part.
// and we are not at the first paragraph in the inset.
if (it->first == 0) if (it->first == 0)
// We are already at the first paragraph in the inset.
return 0; return 0;
// then this is the paragraph we are looking for. // OK, this is the paragraph we are looking for.
pit = it->first - 1; pit = it->first - 1;
// rebreak it and update the CoordCache. newParMetricsUp();
redoParagraph(pit);
par_metrics_[pit].setPosition(it->second.position() - pm.descent());
return pit; return pit;
} }
ParagraphMetrics const & pm_last = par_metrics_[last->first]; ParagraphMetrics const & pm_last = par_metrics_[last->first];
// If we are off-screen (after the visible part) if (y >= last->second.position() + int(pm_last.descent())) {
if (y > bv_->workHeight() // We are looking for a position that is after the last paragraph in
// and even after the first paragraph in the cache. // the cache (which is in priciple off-screen, that is before the
&& y >= last->second.position() + int(pm_last.descent())) { // visible part.
pit = last->first + 1; pit = last->first + 1;
// and we are not at the last paragraph in the inset.
if (pit == int(text_->paragraphs().size())) if (pit == int(text_->paragraphs().size()))
// We are already at the last paragraph in the inset.
return last->first; return last->first;
// then this is the paragraph we are looking for. // OK, this is the paragraph we are looking for.
// rebreak it and update the CoordCache. newParMetricsDown();
redoParagraph(pit);
par_metrics_[pit].setPosition(last->second.position() + pm_last.ascent());
return pit; return pit;
} }