]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
fix crash when collapsing ert with cursor inside
[lyx.git] / src / BufferView.C
index 2be15d5e9009e3e493bc6c649a330df6f615f08f..918d7a3e33c556cc94bdc93fbf9b17fc578a8bd7 100644 (file)
@@ -275,9 +275,7 @@ void BufferView::gotoLabel(string const & label)
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       cursor().clearSelection();
-                       text()->setCursor(cursor(), it.pit(), it.pos());
-                       cursor().resetAnchor();
+                       setCursor(it);
                        update();
                        return;
                }
@@ -290,8 +288,7 @@ void BufferView::hideCursor()
        screen().hideCursor();
 }
 
-
-LyXText * BufferView::getLyXText() const
+LyXText * BufferView::getLyXText()
 {
        LyXText * text = cursor().innerText();
        BOOST_ASSERT(text);
@@ -299,6 +296,14 @@ LyXText * BufferView::getLyXText() const
 }
 
 
+LyXText const * BufferView::getLyXText() const
+{
+       LyXText const * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
+}
+
+
 void BufferView::haveSelection(bool sel)
 {
        pimpl_->workarea().haveSelection(sel);
@@ -317,12 +322,13 @@ LyXText * BufferView::text() const
 }
 
 
-void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
+void BufferView::setCursor(DocIterator const & dit)
 {
-       for (int i = 0, n = par.size(); i < n; ++i)
-               par[i].inset().edit(cursor(), true);
+       size_t const n = dit.depth();
+       for (size_t i = 0; i < n; ++i)
+               dit[i].inset().edit(cursor(), true);
 
-       cursor().setCursor(makeDocIterator(par, pos));
+       cursor().setCursor(dit);
        cursor().selection() = false;
 }
 
@@ -330,11 +336,9 @@ void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
 void BufferView::putSelectionAt(DocIterator const & cur,
                                int length, bool backwards)
 {
-       ParIterator par(cur);
-
        cursor().clearSelection();
 
-       setCursor(par, cur.pos());
+       setCursor(cur);
 
        if (length) {
                if (backwards) {