diff --git a/src/BufferView.cpp b/src/BufferView.cpp index dda37ae335..ac22a4e618 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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_; diff --git a/src/BufferView.h b/src/BufferView.h index f424d433db..901d055223 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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(); diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index e851dc42f0..c2180df5c6 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -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()); + 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()); // FIXME LFUN // If we used an LFUN, we would not need these lines: bv->putSelectionAt(dit, max(range, pos_type(1)), false);