]> git.lyx.org Git - features.git/commitdiff
Fix bug #7361 (Assertion when a latex error occurs in the first (empty) paragraph)
authorEnrico Forestieri <forenr@lyx.org>
Fri, 18 Mar 2011 17:26:17 +0000 (17:26 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 18 Mar 2011 17:26:17 +0000 (17:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37954 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/frontends/qt4/GuiErrorList.cpp

index dda37ae3353b1792d266b512b6c79bc24d562a31..ac22a4e618996a53145199735e6c0df51b551425 100644 (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_;
index f424d433db4d0823601bf48088e991d18e3bcb26..901d05522382c1a473b01d30f857b592a393c54d 100644 (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();
 
index e851dc42f0cf7faabdc63e4bcf26b7ec58fddefd..c2180df5c6f2741a14eebe6e680317114ce87bb0 100644 (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);