]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
more cursor dispatch
[lyx.git] / src / text.C
index a5f41923b8bbc9a14356aa544acd6f3dee056668..5f53767f140a1236abce8e724d44b91e79631c70 100644 (file)
@@ -845,7 +845,7 @@ void LyXText::redoParagraph()
 // same Paragraph one to the right and make a rebreak
 void LyXText::insertChar(char c)
 {
-       recordUndo(Undo::INSERT, this, cursor().par(), cursor().par());
+       recordUndo(bv()->cursor(), Undo::INSERT);
 
        // When the free-spacing option is set for the current layout,
        // disable the double-space checking
@@ -1132,7 +1132,7 @@ void LyXText::acceptChange()
        if (cur.selBegin().par() == cur.par()) {
                CursorSlice const & startc = cur.selBegin();
                CursorSlice const & endc = cur.selEnd();
-               recordUndo(Undo::INSERT, this, startc.par());
+               recordUndo(cur, Undo::INSERT, cur.anchor().par());
                getPar(startc)->acceptChange(startc.pos(), endc.pos());
                finishUndo();
                cur.clearSelection();
@@ -1152,7 +1152,7 @@ void LyXText::rejectChange()
        if (cur.selBegin().par() == cur.selEnd().par()) {
                CursorSlice const & startc = cur.selBegin();
                CursorSlice const & endc = cur.selEnd();
-               recordUndo(Undo::INSERT, this, startc.par());
+               recordUndo(cur, Undo::INSERT, cur.anchor().par());
                getPar(startc)->rejectChange(startc.pos(), endc.pos());
                finishUndo();
                cur.clearSelection();
@@ -1240,7 +1240,7 @@ void LyXText::changeCase(LyXText::TextCase action)
                setCursor(to.par(), to.pos() + 1);
        }
 
-       recordUndo(Undo::ATOMIC, this, from.par(), to.par());
+       recordUndo(cur, Undo::ATOMIC, cur.anchor().par());
 
        pos_type pos = from.pos();
        int par = from.par();
@@ -1284,9 +1284,9 @@ void LyXText::Delete()
        cursorRight(true);
 
        // if you had success make a backspace
-       if (old_cursor.par() != cursor().par() || old_cursor.pos() !=
-cursor().pos()) {
-               recordUndo(Undo::DELETE, this, old_cursor.par());
+       if (old_cursor.par() != cursor().par()
+           || old_cursor.pos() != cursor().pos()) {
+               recordUndo(bv()->cursor(), Undo::DELETE, old_cursor.par());
                backspace();
        }
 }
@@ -1325,7 +1325,7 @@ void LyXText::backspace()
                }
 
                if (cursor().par() != 0)
-                       recordUndo(Undo::DELETE, this, cursor().par() - 1, cursor().par());
+                       recordUndo(bv()->cursor(), Undo::DELETE, cursor().par() - 1);
 
                ParagraphList::iterator tmppit = cursorPar();
                // We used to do cursorLeftIntern() here, but it is
@@ -1364,7 +1364,7 @@ void LyXText::backspace()
        } else {
                // this is the code for a normal backspace, not pasting
                // any paragraphs
-               recordUndo(Undo::DELETE, this, cursor().par());
+               recordUndo(bv()->cursor(), Undo::DELETE);
                // We used to do cursorLeftIntern() here, but it is
                // not a good idea since it triggers the auto-delete
                // mechanism. So we do a cursorLeftIntern()-lite,
@@ -1385,6 +1385,8 @@ void LyXText::backspace()
 
 ParagraphList::iterator LyXText::cursorPar() const
 {
+       //lyxerr << "### cursorPar: cursor: " << bv()->cursor() << endl;
+       //lyxerr << "xxx cursorPar: cursor: " << cursor() << endl;
        return getPar(cursor().par());
 }
 
@@ -1403,6 +1405,7 @@ ParagraphList::iterator LyXText::getPar(CursorSlice const & cur) const
 
 ParagraphList::iterator LyXText::getPar(int par) const
 {
+       //lyxerr << "getPar: " << par << " from " << paragraphs().size() << endl;
        BOOST_ASSERT(par >= 0);
        BOOST_ASSERT(par < int(paragraphs().size()));
        ParagraphList::iterator pit = paragraphs().begin();
@@ -1414,7 +1417,6 @@ ParagraphList::iterator LyXText::getPar(int par) const
 RowList::iterator
 LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
 {
-       //lyxerr << "getRowNearY: y " << y << endl;
 #if 1
        ParagraphList::iterator const
                pend = boost::prior(paragraphs().end());
@@ -1455,36 +1457,18 @@ RowList::iterator LyXText::firstRow() const
 }
 
 
-ParagraphList::iterator LyXText::firstPar() const
-{
-       return paragraphs().begin();
-}
-
-
 RowList::iterator LyXText::lastRow() const
 {
        return boost::prior(endRow());
 }
 
 
-ParagraphList::iterator LyXText::lastPar() const
-{
-       return boost::prior(endPar());
-}
-
-
 RowList::iterator LyXText::endRow() const
 {
        return paragraphs().back().rows.end();
 }
 
 
-ParagraphList::iterator LyXText::endPar() const
-{
-       return paragraphs().end();
-}
-
-
 void LyXText::nextRow(ParagraphList::iterator & pit,
        RowList::iterator & rit) const
 {
@@ -1862,23 +1846,11 @@ int LyXText::descent() const
 }
 
 
-int LyXText::cursorX() const
-{
-       return cursorX(cursor());
-}
-
-
-int LyXText::cursorY() const
-{
-       return cursorY(cursor());
-}
-
-
 int LyXText::cursorX(CursorSlice const & cur) const
 {
        ParagraphList::iterator pit = getPar(cur);
        if (pit->rows.empty())
-               return 0;
+               return xo_;
        Row const & row         = *pit->getRow(cur.pos());
        pos_type pos            = cur.pos();
        pos_type cursor_vpos    = 0;
@@ -1931,7 +1903,7 @@ int LyXText::cursorX(CursorSlice const & cur) const
                } else
                        x += singleWidth(pit, pos);
        }
-       return int(x);
+       return xo_ + int(x);
 }
 
 
@@ -1939,29 +1911,30 @@ int LyXText::cursorY(CursorSlice const & cur) const
 {
        Paragraph & par = *getPar(cur);
        Row & row = *par.getRow(cur.pos());
-       return par.y + row.y_offset() + row.baseline();
+       return yo_ + par.y + row.y_offset() + row.baseline();
 }
 
 
 CursorSlice & LyXText::cursor()
 {
-       return bv()->cursor().cursor_.back();
+       //lyxerr << "# accessing slice " << findText(this) << endl;
+       if (this != bv()->cursor().text()) {
+               lyxerr << "cursor: " << bv()->cursor()
+                       << "\ntext: " << bv()->cursor().text() 
+                       << "\nthis: " << this << endl;
+               BOOST_ASSERT(false);
+       }
+       return bv()->cursor().current();
 }
 
 
 CursorSlice const & LyXText::cursor() const
 {
-       return bv()->cursor().cursor_.back();
-}
-
-
-CursorSlice & LyXText::anchor()
-{
-       return bv()->cursor().anchor_.back();
-}
-
-
-CursorSlice const & LyXText::anchor() const
-{
-       return bv()->cursor().anchor_.back();
+       if (this != bv()->cursor().text()) {
+               lyxerr << "cursor: " << bv()->cursor()
+                       << "\ntext: " << bv()->cursor().text() 
+                       << "\nthis: " << this << endl;
+               BOOST_ASSERT(false);
+       }
+       return bv()->cursor().current();
 }