Fix bug #7361 (Assertion when a latex error occurs in the first (empty) paragraph)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37954 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2011-03-18 17:26:17 +00:00
parent 6169919428
commit 397c03b433
3 changed files with 49 additions and 5 deletions

View File

@ -2364,6 +2364,42 @@ void BufferView::putSelectionAt(DocIterator const & cur,
}
bool BufferView::selectIfEmpty(DocIterator & cur)
{
if (!cur.paragraph().empty())
return false;
pit_type const beg_pit = cur.pit();
if (beg_pit > 0) {
// The paragraph associated to this item isn't
// the first one, so it can be selected
cur.backwardPos();
} else {
// We have to resort to select the space between the
// end of this item and the begin of the next one
cur.forwardPos();
}
if (cur.empty()) {
// If it is the only item in the document,
// nothing can be selected
return false;
}
pit_type const end_pit = cur.pit();
pos_type const end_pos = cur.pos();
d->cursor_.clearSelection();
d->cursor_.reset();
d->cursor_.setCursor(cur);
d->cursor_.pit() = beg_pit;
d->cursor_.pos() = 0;
d->cursor_.setSelection(false);
d->cursor_.resetAnchor();
d->cursor_.pit() = end_pit;
d->cursor_.pos() = end_pos;
d->cursor_.setSelection();
return true;
}
Cursor & BufferView::cursor()
{
return d->cursor_;

View File

@ -247,6 +247,9 @@ public:
void putSelectionAt(DocIterator const & cur,
int length, bool backwards);
/// selects the item at cursor if its paragraph is empty.
bool selectIfEmpty(DocIterator & cur);
/// update the internal \c ViewMetricsInfo.
void updateMetrics();

View File

@ -172,11 +172,17 @@ bool GuiErrorList::goTo(int item)
return false;
}
// If this paragraph is empty, highlight the previous one
while (dit.paragraph().empty())
dit.backwardPos();
// Now make the selection.
BufferView * bv = const_cast<BufferView *>(bufferview());
if (bv->selectIfEmpty(dit)) {
// The paragraph is empty but can be selected
bv->processUpdateFlags(Update::Force | Update::FitCursor);
return true;
}
if (dit.empty()) {
// The paragraph is empty and cannot be selected
return false;
}
// if pos_end is 0, this means it is end-of-paragraph
pos_type const s = dit.paragraph().size();
pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
@ -184,7 +190,6 @@ bool GuiErrorList::goTo(int item)
pos_type const range = end == start ? s - start : end - start;
// end-of-paragraph cannot be highlighted, so highlight the last thing
dit.pos() = range ? start : end - 1;
BufferView * bv = const_cast<BufferView *>(bufferview());
// FIXME LFUN
// If we used an LFUN, we would not need these lines:
bv->putSelectionAt(dit, max(range, pos_type(1)), false);