]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
more cursor dispatch
[lyx.git] / src / BufferView.C
index 58d13607621a5d9c3fde024928cedd9a15db6330..d1ff326a342b1ed739c172f98612c333a29d6fc8 100644 (file)
 using lyx::support::bformat;
 using lyx::support::MakeAbsPath;
 
+using std::distance;
 using std::find;
 using std::string;
+using std::swap;
 using std::vector;
 
 
@@ -314,7 +316,7 @@ void BufferView::gotoLabel(string const & label)
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
                        cursor().clearSelection();
                        text()->setCursor(
-                               std::distance(text()->paragraphs().begin(), it.getPar()),
+                               distance(text()->paragraphs().begin(), it.getPar()),
                                it.getPos());
                        cursor().resetAnchor();
                        update();
@@ -331,7 +333,7 @@ void BufferView::undo()
 
        owner()->message(_("Undo"));
        cursor().clearSelection();
-       if (!textUndo(this))
+       if (!textUndo(*this))
                owner()->message(_("No further undo information"));
        update();
        switchKeyMap();
@@ -345,7 +347,7 @@ void BufferView::redo()
 
        owner()->message(_("Redo"));
        cursor().clearSelection();
-       if (!textRedo(this))
+       if (!textRedo(*this))
                owner()->message(_("No further redo information"));
        update();
        switchKeyMap();
@@ -442,6 +444,19 @@ LyXText * BufferView::text() const
 }
 
 
+void BufferView::setCursor(ParIterator const & par,
+                          lyx::pos_type pos)
+{
+       LCursor & cur = cursor();
+       cur.reset();
+       ParIterator::PosHolder const & positions = par.positions();
+       int const last = par.size() - 1;
+       for (int i = 0; i < last; ++i)
+               (*positions[i].it)->inset->edit(cur, true);
+       cur.resetAnchor();
+       LyXText * lt = par.text(*buffer());
+       lt->setCursor(par.pit(), pos);
+}
 
 
 /*
@@ -462,11 +477,12 @@ void BufferView::putSelectionAt(PosIterator const & cur,
                      int length, bool backwards)
 {
        ParIterator par(cur);
-       
+
        cursor().clearSelection();
 
        LyXText * text = par.text(*buffer());
-       par.lockPath(this);
+       setCursor(par, cur.pos());
+       
        // hack for the chicken and egg problem
        if (par.inset())
                top_y(par.outerPar()->y);
@@ -478,7 +494,7 @@ void BufferView::putSelectionAt(PosIterator const & cur,
                text->setSelectionRange(length);
                cursor().setSelection();
                if (backwards)
-                       std::swap(cursor().cursor_, cursor().anchor_);
+                       swap(cursor().cursor_, cursor().anchor_);
        }
 
        fitCursor();
@@ -496,4 +512,3 @@ LCursor const & BufferView::cursor() const
 {
        return pimpl_->cursor_;
 }
-