]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
more cursor dispatch
[lyx.git] / src / text2.C
index 3aa14065e64f7b1e305d9ca1210be7fda80f5249..e15775524e164ac99ef5fd351930390432dac074 100644 (file)
@@ -79,9 +79,9 @@ LyXText::LyXText(BufferView * bv, bool in_inset)
 {}
 
 
-void LyXText::init(BufferView * bview)
+void LyXText::init(BufferView * bv)
 {
-       bv_owner = bview;
+       bv_owner = bv;
 
        ParagraphList::iterator const beg = paragraphs().begin();
        ParagraphList::iterator const end = paragraphs().end();
@@ -94,8 +94,7 @@ void LyXText::init(BufferView * bview)
        current_font = getFont(beg, 0);
 
        redoParagraphs(beg, end);
-       setCursorIntern(0, 0);
-       bv()->cursor().resetAnchor();
+       bv->cursor().resetAnchor();
 
        updateCounters();
 }
@@ -214,38 +213,6 @@ void LyXText::setCharFont(
 }
 
 
-InsetBase * LyXText::getInset() const
-{
-       ParagraphList::iterator pit = cursorPar();
-       pos_type const pos = cursor().pos();
-
-       if (pos < pit->size() && pit->isInset(pos)) {
-               return pit->getInset(pos);
-       }
-       return 0;
-}
-
-
-bool LyXText::toggleInset()
-{
-       InsetBase * inset = getInset();
-       // is there an editable inset at cursor position?
-       if (!isEditableInset(inset))
-               return false;
-       //bv()->owner()->message(inset->editMessage());
-
-       // do we want to keep this?? (JMarc)
-       if (!isHighlyEditableInset(inset))
-               recUndo(cursor().par());
-
-       if (inset->isOpen())
-               inset->close();
-       else
-               inset->open();
-       return true;
-}
-
-
 // used in setLayout
 // Asger is not sure we want to do this...
 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
@@ -1087,8 +1054,7 @@ void LyXText::insertStringAsLines(string const & str)
        ParagraphList::iterator pit = cursorPar();
        pos_type pos = cursor().pos();
        ParagraphList::iterator endpit = boost::next(cursorPar());
-
-       recUndo(cursor().par());
+       recordUndo(cur, Undo::ATOMIC);
 
        // only to be sure, should not be neccessary
        cur.clearSelection();
@@ -1458,10 +1424,11 @@ DispatchResult LyXText::moveLeftIntern(bool front,
 
 DispatchResult LyXText::moveUp()
 {
-       if (cursorPar() == firstPar() && cursorRow() == firstRow())
+       LCursor & cur = bv()->cursor();
+       if (cur.par() == 0 && cursorRow() == firstRow())
                return DispatchResult(false, FINISHED_UP);
        cursorUp(false);
-       bv()->cursor().clearSelection();
+       cur.clearSelection();
        return DispatchResult(true);
 }
 
@@ -1469,7 +1436,7 @@ DispatchResult LyXText::moveUp()
 DispatchResult LyXText::moveDown()
 {
        LCursor & cur = bv()->cursor();
-       if (cursorPar() == lastPar() && cursorRow() == lastRow())
+       if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
                return DispatchResult(false, FINISHED_DOWN);
        cursorDown(false);
        cur.clearSelection();
@@ -1739,13 +1706,13 @@ ParagraphList & LyXText::paragraphs() const
 
 void LyXText::recUndo(paroffset_type first, paroffset_type last) const
 {
-       recordUndo(Undo::ATOMIC, this, first, last);
+       recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
 }
 
 
 void LyXText::recUndo(lyx::paroffset_type par) const
 {
-       recordUndo(Undo::ATOMIC, this, par, par);
+       recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
 }
 
 
@@ -1755,6 +1722,26 @@ bool LyXText::isInInset() const
 }
 
 
+bool LyXText::toggleInset()
+{
+       InsetBase * inset = bv()->cursor().nextInset();
+       // is there an editable inset at cursor position?
+       if (!isEditableInset(inset))
+               return false;
+       //bv()->owner()->message(inset->editMessage());
+
+       // do we want to keep this?? (JMarc)
+       if (!isHighlyEditableInset(inset))
+               recUndo(cursor().par());
+
+       if (inset->isOpen())
+               inset->close();
+       else
+               inset->open();
+       return true;
+}
+
+
 int defaultRowHeight()
 {
        return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) *  1.2);