Currently we have cursor left/right/up/down handled twice (once in
InsetText and once in LyXText). There is no real reason that both can't
be combined. This is a first step by moving the somewhat more powerful
version from InsetText to LyXText. Both versions are still used...

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
? .text.C.swp
? 1.diff
? 1.diff.gz
? 2.diff
? 3.diff
? ?t
? fullredraw.diff
? par-row.diff
? textcache.diff
? insets/.insettext.h.swp
? insets/1.diff
? mathed/cursor.diff
? support/1.diff
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.463
diff -u -p -r1.463 BufferView_pimpl.C
--- BufferView_pimpl.C  13 Nov 2003 20:16:33 -0000      1.463
+++ BufferView_pimpl.C  17 Nov 2003 14:19:25 -0000
@@ -872,16 +872,21 @@ namespace {
                theTempCursor = LCursor(bv);
                while (true) {
                        InsetOld * inset_hit = text->checkInsetHit(x, y);
-                       if (!inset_hit)
+                       if (!inset_hit) {
+                               lyxerr << "no further inset hit" << endl;
                                break;
+                       }
                        inset = inset_hit;
-                       if (!inset_hit->descendable())
+                       if (!inset_hit->descendable()) {
+                               lyxerr << "not descendable" << endl;
                                break;
+                       }
                        text = inset_hit->getText(0);
                        lyxerr << "Hit inset: " << inset << " at x: " << x
                                << " text: " << text << " y: " << y << endl;
                        theTempCursor.push(static_cast<UpdatableInset*>(inset));
                }
+               lyxerr << "theTempCursor: " << theTempCursor << endl;
                return inset;
        }
 
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.254
diff -u -p -r1.254 lyxtext.h
--- lyxtext.h   11 Nov 2003 10:08:32 -0000      1.254
+++ lyxtext.h   17 Nov 2003 14:19:25 -0000
@@ -227,9 +227,9 @@ public:
        ///
        void cursorDown(bool selecting = false);
        ///
-       void cursorLeft(bool internal = true);
+       bool cursorLeft(bool internal = true);
        ///
-       void cursorRight(bool internal = true);
+       bool cursorRight(bool internal = true);
        ///
        void cursorLeftOneWord();
        ///
@@ -443,6 +443,24 @@ public:
        void cursorLeftOneWord(LyXCursor &);
        ///
        void cursorRightOneWord(LyXCursor &);
+
+       ///
+       DispatchResult moveRight();
+       ///
+       DispatchResult moveLeft();
+       ///
+       DispatchResult moveRightIntern(bool front,
+               bool activate_inset, bool selecting);
+       ///
+       DispatchResult moveLeftIntern(bool front,
+               bool activate_inset, bool selecting);
+       ///
+       DispatchResult moveUp();
+       ///
+       DispatchResult moveDown();
+       ///
+       bool checkAndActivateInset(bool front);
+
 
 private:
        /** Cursor related data.
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.497
diff -u -p -r1.497 text.C
--- text.C      13 Nov 2003 13:43:39 -0000      1.497
+++ text.C      17 Nov 2003 14:19:25 -0000
@@ -1785,3 +1785,84 @@ void LyXText::getWord(LyXCursor & from, 
                to.pos(to.pos() + 1);
        }
 }
+
+
+
+bool LyXText::checkAndActivateInset(bool front)
+{
+       if (cursor.pos() == cursorPar()->size())
+               return false;
+       InsetOld * inset = cursorPar()->getInset(cursor.pos());
+       if (!isHighlyEditableInset(inset))
+               return false;
+       inset->edit(bv(), front);
+       return true;
+}
+
+
+DispatchResult LyXText::moveRight()
+{
+       if (cursorPar()->isRightToLeftPar(bv()->buffer()->params()))
+               return moveLeftIntern(false, true, false);
+       else
+               return moveRightIntern(true, true, false);
+}
+
+
+DispatchResult LyXText::moveLeft()
+{
+       if (cursorPar()->isRightToLeftPar(bv()->buffer()->params()))
+               return moveRightIntern(true, true, false);
+       else
+               return moveLeftIntern(false, true, false);
+}
+
+
+DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool 
selecting)
+{
+       ParagraphList::iterator c_par = cursorPar();
+       if (boost::next(c_par) == ownerParagraphs().end()
+               && cursor.pos() >= c_par->size())
+               return DispatchResult(false, FINISHED_RIGHT);
+       if (activate_inset && checkAndActivateInset(front))
+               return DispatchResult(true, true);
+       cursorRight(bv());
+       if (!selecting)
+               clearSelection();
+       return DispatchResult(true);
+}
+
+
+DispatchResult LyXText::moveLeftIntern(bool front,
+                         bool activate_inset, bool selecting)
+{
+       if (cursor.par() == 0 && cursor.pos() <= 0)
+               return DispatchResult(false, FINISHED);
+       cursorLeft(bv());
+       if (!selecting)
+               clearSelection();
+       if (activate_inset && checkAndActivateInset(front))
+               return DispatchResult(true, true);
+       return DispatchResult(true);
+}
+
+
+DispatchResult LyXText::moveUp()
+{
+       if (cursorRow() == firstRow())
+               return DispatchResult(false, FINISHED_UP);
+       cursorUp(bv());
+       clearSelection();
+       return DispatchResult(true);
+}
+
+
+DispatchResult LyXText::moveDown()
+{
+       if (cursorRow() == lastRow())
+               return DispatchResult(false, FINISHED_DOWN);
+       cursorDown(bv());
+       clearSelection();
+       return DispatchResult(true);
+}
+
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.500
diff -u -p -r1.500 text2.C
--- text2.C     13 Nov 2003 13:43:40 -0000      1.500
+++ text2.C     17 Nov 2003 14:19:25 -0000
@@ -1580,7 +1580,7 @@ void LyXText::setCursorFromCoordinates(L
 }
 
 
-void LyXText::cursorLeft(bool internal)
+bool LyXText::cursorLeft(bool internal)
 {
        if (cursor.pos() > 0) {
                bool boundary = cursor.boundary();
@@ -1588,28 +1588,40 @@ void LyXText::cursorLeft(bool internal)
                if (!internal && !boundary &&
                    bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1))
                        setCursor(cursor.par(), cursor.pos() + 1, true, true);
-       } else if (cursor.par() != 0) {
+               return true;
+       }
+
+       if (cursor.par() != 0) {
                // steps into the paragraph above
                setCursor(cursor.par() - 1, boost::prior(cursorPar())->size());
+               return true;
        }
+
+       return false;
 }
 
 
-void LyXText::cursorRight(bool internal)
+bool LyXText::cursorRight(bool internal)
 {
-       bool const at_end = (cursor.pos() == cursorPar()->size());
-       bool const at_newline = !at_end &&
-               cursorPar()->isNewline(cursor.pos());
-
-       if (!internal && cursor.boundary() && !at_newline)
+       if (!internal && cursor.boundary()) {
                setCursor(cursor.par(), cursor.pos(), true, false);
-       else if (!at_end) {
+               return true;
+       }
+
+       if (cursor.pos() != cursorPar()->size()) {
                setCursor(cursor.par(), cursor.pos() + 1, true, false);
                if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(),
                                                 cursor.pos()))
                        setCursor(cursor.par(), cursor.pos(), true, true);
-       } else if (cursor.par() + 1 != int(ownerParagraphs().size()))
+               return true;
+       }
+
+       if (cursor.par() + 1 != int(ownerParagraphs().size())) {
                setCursor(cursor.par() + 1, 0);
+               return true;
+       }
+
+       return false;
 }
 
 
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.543
diff -u -p -r1.543 insettext.C
--- insets/insettext.C  17 Nov 2003 13:20:34 -0000      1.543
+++ insets/insettext.C  17 Nov 2003 14:19:25 -0000
@@ -462,23 +462,23 @@ DispatchResult InsetText::priv_dispatch(
                break;
 
        case LFUN_RIGHT:
-               result = moveRight(bv);
+               result = text_.moveRight();
                finishUndo();
                break;
 
        case LFUN_LEFT:
                finishUndo();
-               result = moveLeft(bv);
+               result = text_.moveLeft();
                break;
 
        case LFUN_DOWN:
                finishUndo();
-               result = moveDown(bv);
+               result = text_.moveDown();
                break;
 
        case LFUN_UP:
                finishUndo();
-               result = moveUp(bv);
+               result = text_.moveUp();
                break;
 
        case LFUN_PRIOR:
@@ -674,73 +674,6 @@ int InsetText::insetInInsetY() const
 }
 
 
-DispatchResult InsetText::moveRight(BufferView * bv)
-{
-       if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))
-               return moveLeftIntern(bv, false, true, false);
-       else
-               return moveRightIntern(bv, true, true, false);
-}
-
-
-DispatchResult InsetText::moveLeft(BufferView * bv)
-{
-       if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))
-               return moveRightIntern(bv, true, true, false);
-       else
-               return moveLeftIntern(bv, false, true, false);
-}
-
-
-DispatchResult InsetText::moveRightIntern(BufferView * bv, bool front,
-                          bool activate_inset, bool selecting)
-{
-       ParagraphList::iterator c_par = cpar();
-       if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
-               return DispatchResult(false, FINISHED_RIGHT);
-       if (activate_inset && checkAndActivateInset(bv, front))
-               return DispatchResult(true, true);
-       text_.cursorRight(bv);
-       if (!selecting)
-               text_.clearSelection();
-       return DispatchResult(true);
-}
-
-
-DispatchResult InsetText::moveLeftIntern(BufferView * bv, bool front,
-                         bool activate_inset, bool selecting)
-{
-       if (cpar() == paragraphs.begin() && cpos() <= 0)
-               return DispatchResult(false, FINISHED);
-       text_.cursorLeft(bv);
-       if (!selecting)
-               text_.clearSelection();
-       if (activate_inset && checkAndActivateInset(bv, front))
-               return DispatchResult(true, true);
-       return DispatchResult(true);
-}
-
-
-DispatchResult InsetText::moveUp(BufferView * bv)
-{
-       if (crow() == text_.firstRow())
-               return DispatchResult(false, FINISHED_UP);
-       text_.cursorUp(bv);
-       text_.clearSelection();
-       return DispatchResult(true);
-}
-
-
-DispatchResult InsetText::moveDown(BufferView * bv)
-{
-       if (crow() == text_.lastRow())
-               return DispatchResult(false, FINISHED_DOWN);
-       text_.cursorDown(bv);
-       text_.clearSelection();
-       return DispatchResult(true);
-}
-
-
 bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
 {
        inset->setOwner(this);
@@ -814,19 +747,6 @@ void InsetText::setFont(BufferView * bv,
 
 //     bv->fitCursor();
        updateLocal(bv, true);
-}
-
-
-bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
-{
-       if (cpos() == cpar()->size())
-               return false;
-       InsetOld * inset = cpar()->getInset(cpos());
-       if (!isHighlyEditableInset(inset))
-               return false;
-       inset->edit(bv, front);
-       updateLocal(bv, false);
-       return true;
 }
 
 
Index: insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.230
diff -u -p -r1.230 insettext.h
--- insets/insettext.h  17 Nov 2003 12:39:24 -0000      1.230
+++ insets/insettext.h  17 Nov 2003 14:19:25 -0000
@@ -186,30 +186,8 @@ private:
        // If the inset is empty set the language of the current font to the
        // language to the surronding text (if different).
        void sanitizeEmptyText(BufferView *);
-
-       ///
-       DispatchResult moveRight(BufferView *);
-       ///
-       DispatchResult moveLeft(BufferView *);
-       ///
-       DispatchResult moveRightIntern(BufferView *, bool front,
-                                              bool activate_inset = true,
-                                              bool selecting = false);
-       ///
-       DispatchResult moveLeftIntern(BufferView *, bool front,
-                                             bool activate_inset = true,
-                                             bool selecting = false);
-
-       ///
-       DispatchResult moveUp(BufferView *);
-       ///
-       DispatchResult moveDown(BufferView *);
        ///
        void setCharFont(Buffer const &, int pos, LyXFont const & font);
-       ///
-       bool checkAndActivateInset(BufferView * bv, bool front);
-       ///
-       bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0);
        ///
        void removeNewlines();
        ///

Reply via email to