Am 14.06.2007 um 10:39 schrieb Jean-Marc Lasgouttes:

"Stefan" == Stefan Schimanski <[EMAIL PROTECTED]> writes:

Stefan> If we want this, another OK is needed. Stefan

I missed the latest patch. COuld you report it please?

Sure, inlined and attached:

Index: lyx-devel/src/Cursor.cpp
===================================================================
--- lyx-devel.orig/src/Cursor.cpp       2007-06-13 08:30:09.000000000 +0200
+++ lyx-devel/src/Cursor.cpp    2007-06-13 08:35:38.000000000 +0200
@@ -301,8 +301,7 @@
        
        // store some values to be used inside of the handlers
        getPos(beforeDispX_, beforeDispY_);
-       beforeDispDepth_ = depth();
-       
+       beforeDispatchCursor_ = *this;
        for (; depth(); pop()) {
                LYXERR(Debug::DEBUG) << "Cursor::dispatch: cmd: "
                        << cmd0 << endl << *this << endl;
@@ -319,6 +318,7 @@
                if (disp_.dispatched())
                        break;
        }
+       
        // it completely to get a 'bomb early' behaviour in case this
        // object will be used again.
        if (!disp_.dispatched()) {
@@ -326,6 +326,10 @@
                operator=(safe);
                disp_.update(Update::None);
                disp_.dispatched(false);
+       } else {
+               // restore the previous one because nested Cursor::dispatch 
calls
+               // are possible which would change it
+               beforeDispatchCursor_ = safe.beforeDispatchCursor_;
        }
 }

@@ -1183,7 +1187,8 @@
        // if we cannot move up/down inside this inset anymore
        if (x_target_ == -1)
                setTargetX(xo);
- else if (xo - textTargetOffset() != x_target() && depth() == beforeDispDepth_) {
+       else if (xo - textTargetOffset() != x_target() &&
+                                        depth() == 
beforeDispatchCursor_.depth()) {
// In text mode inside the line (not left or right) possibly set a new target_x, // but only if we are somewhere else than the previous target- offset.
                
@@ -1229,7 +1234,7 @@
                                row + 1 >= int(pm.rows().size()))
                        return false;
        }       
-       
+
        // with and without selection are handled differently
        if (!selection()) {
                int yo = bv_funcs::getPos(bv(), *this, boundary()).y_;
@@ -1272,10 +1277,10 @@
                                top().pos() = std::min(tm.x2pos(pit(), 0, xo), 
top().lastpos());
                        }
                }
-               
+
                updateNeeded |= bv().checkDepm(*this, old);
        }
-       
+
        updateTextTargetOffset();
        return true;
 }      
@@ -1483,4 +1488,24 @@
 }


+bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
+{
+       // find inset in common
+       size_type i;
+       for (i = 0; i < old.depth() && i < cur.depth(); ++i) {
+               if (&old.inset() != &cur.inset())
+                       break;
+       }
+       
+       // notify everything on top of the common part in old cursor,
+       // but stop if the inset claims the cursor to be invalid now
+       for (;  i < old.depth(); ++i) {
+               if (old[i].inset().notifyCursorLeaves(cur))
+                       return true;
+       }
+       
+       return false;
+}
+
+
 } // namespace lyx
Index: lyx-devel/src/Cursor.h
===================================================================
--- lyx-devel.orig/src/Cursor.h 2007-06-13 08:30:09.000000000 +0200
+++ lyx-devel/src/Cursor.h      2007-06-13 08:35:38.000000000 +0200
@@ -86,9 +86,9 @@
        DocIterator selectionBegin() const;
        /// access start of selection
        DocIterator selectionEnd() const;
-       ///
+       /// FIXME: document this
        bool selHandle(bool selecting);
-       //
+       ///
        docstring selectionAsString(bool label) const;
        ///
        docstring currentState();
@@ -194,6 +194,8 @@
        
        ///
        DispatchResult disp_;
+       ///
+ DocIterator const & beforeDispatchCursor() { return beforeDispatchCursor_; }
        
 private:
        /**
@@ -225,8 +227,8 @@
        /// y position before dispatch started
        int beforeDispY_;
        /// position before dispatch started
-       size_t beforeDispDepth_;
-               
+       DocIterator beforeDispatchCursor_;
+
 private:

        //
@@ -296,6 +298,7 @@
        bool isInside(Inset const *);

        /// make sure cursor position is valid
+       /// FIXME: It does a subset of fixIfBroken. Maybe merge them?
        void normalize();
        /// mark current cursor trace for redraw
        void touch();
@@ -328,6 +331,13 @@
 };


+/**
+ * Notifies all insets which appear in old, but not in cur. Make
+ * Sure that the cursor old is valid, i.e. als inset pointer
+ * point to valid insets! Use Cursor::fixIfBroken if necessary.
+ */
+bool notifyCursorLeaves(DocIterator const & old, Cursor & cur);
+

 } // namespace lyx

Index: lyx-devel/src/Text3.cpp
===================================================================
--- lyx-devel.orig/src/Text3.cpp        2007-06-13 08:35:11.000000000 +0200
+++ lyx-devel/src/Text3.cpp     2007-06-13 09:31:15.000000000 +0200
@@ -510,25 +510,25 @@
                        saveSelection(cur);
                break;

+       case LFUN_UP_SELECT:
+       case LFUN_DOWN_SELECT:
+               needsUpdate |= cur.selHandle(select);
        case LFUN_UP:
-       case LFUN_UP_SELECT: {
-               //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
-               needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
-               bool const successful = cur.upDownInText(true, needsUpdate);
-               if (!successful)
-                       cur.undispatched();
-               if (cur.selection())
-                       saveSelection(cur);
-               break;
-       }
-
-       case LFUN_DOWN:
-       case LFUN_DOWN_SELECT: {
-               //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
-               needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
-               bool const successful = cur.upDownInText(false, needsUpdate);
-               if (!successful)
+       case LFUN_DOWN: {
+               // move cursor up/down
+               bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
+               bool const successful = cur.upDownInText(up, needsUpdate);
+               if (successful) {
+                       // notify insets which were left and get their update 
flags
+                       notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
+                       cur.fixIfBroken();
+                       
+                       // redraw if you leave mathed (for the decorations)
+                       needsUpdate |= cur.beforeDispatchCursor().inMathed();
+               } else
                        cur.undispatched();
+               
+               // save new selection
                if (cur.selection())
                        saveSelection(cur);
                break;
Index: lyx-devel/src/insets/Inset.h
===================================================================
--- lyx-devel.orig/src/insets/Inset.h 2007-06-13 08:30:09.000000000 +0200
+++ lyx-devel/src/insets/Inset.h        2007-06-13 08:35:38.000000000 +0200
@@ -522,7 +522,6 @@
* It can be forward-declared and passed as a function argument without
  *  having to expose Inset.h.
  */
-
 class Inset_code {
        Inset::Code val_;
 public:
Index: lyx-devel/src/mathed/InsetMathNest.cpp
===================================================================
--- lyx-devel.orig/src/mathed/InsetMathNest.cpp 2007-06-13 08:30:33.000000000 +0200 +++ lyx-devel/src/mathed/InsetMathNest.cpp 2007-06-13 08:35:38.000000000 +0200
@@ -545,35 +545,33 @@
                }
                break;

-       case LFUN_UP:
-               cur.updateFlags(Update::Decoration | Update::FitCursor);
-       case LFUN_UP_SELECT:
- // FIXME Tried to use clearTargetX and macroModeClose, crashed on cur.up()
-               if (cur.inMacroMode()) {
-                       // Make Helge happy
-                       cur.macroModeClose();
-                       break;
-               }
-               cur.selHandle(cmd.action == LFUN_UP_SELECT);
-               if (!cur.upDownInMath(true))
-                       cur.undispatched();
-               // fixes bug 1598. Please check!
-               cur.normalize();
-               break;
-
        case LFUN_DOWN:
+       case LFUN_UP:
                cur.updateFlags(Update::Decoration | Update::FitCursor);
-       case LFUN_DOWN_SELECT:
+       case LFUN_DOWN_SELECT:
+       case LFUN_UP_SELECT: {
+               // close active macro
                if (cur.inMacroMode()) {
                        cur.macroModeClose();
                        break;
                }
-               cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
-               if (!cur.upDownInMath(false))
+               
+               // stop/start the selection
+               bool select = cmd.action == LFUN_DOWN_SELECT ||
+                       cmd.action == LFUN_UP_SELECT;
+               cur.selHandle(select);
+               
+               // go up/down
+               bool up = cmd.action == LFUN_UP || cmd.action == LFUN_UP_SELECT;
+               bool successful = cur.upDownInMath(up);
+               if (successful) {
+                       // notify left insets and give them chance to set 
update flags
+                       lyx::notifyCursorLeaves(cur.beforeDispatchCursor(), 
cur);
+                       cur.fixIfBroken();
+               }       else
                        cur.undispatched();
-               // fixes bug 1598. Please check!
-               cur.normalize();
                break;
+       }

        case LFUN_MOUSE_DOUBLE:
        case LFUN_MOUSE_TRIPLE:


Attachment: notifycursorleaves.patch
Description: Binary data

Attachment: PGP.sig
Description: Signierter Teil der Nachricht

Reply via email to