]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
* Text3.cpp (doDispatch): fix the behaviour of word-delete-forward,
[lyx.git] / src / Cursor.cpp
index d34f348d7307de57cb7324e85ef93025fc201109..a603ed2a19a7c1352d48fcd91510b6fb799a9bc5 100644 (file)
@@ -301,8 +301,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
        
        // 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 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                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 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                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 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
        // 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 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                                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 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                                top().pos() = std::min(tm.x2pos(pit(), 0, xo), top().lastpos());
                        }
                }
-               
+
                updateNeeded |= bv().checkDepm(*this, old);
        }
-       
+
        updateTextTargetOffset();
        return true;
 }      
@@ -1438,18 +1443,36 @@ void Cursor::noUpdate()
 
 Font Cursor::getFont() const
 {
+       // The logic here should more or less match to the Text::setCurrentFont
+       // logic, i.e. the cursor height should give a hint what will happen
+       // if a character is entered.
+       
        // HACK. far from being perfect...
-       int s = 0;
        // go up until first non-0 text is hit
        // (innermost text is 0 in mathed)
+       int s = 0;
        for (s = depth() - 1; s >= 0; --s)
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
        Text const & text = *sl.text();
-       Font font = text.getPar(sl.pit()).getFont(
-               bv().buffer()->params(),
-               sl.pos(),
+       Paragraph const & par = text.getPar(sl.pit());
+       
+       // on boundary, so we are really at the character before
+       pos_type pos = sl.pos();
+       if (pos > 0 && boundary())
+               --pos;
+       
+       // on space? Take the font before (only for RTL boundary stay)
+       if (pos > 0) {
+               if (pos == sl.lastpos()
+                               || (par.isSeparator(pos) && 
+                                               !text.isRTLBoundary(buffer(), par, pos)))
+                       --pos;
+       }
+       
+       // get font at the position
+       Font font = par.getFont(bv().buffer()->params(), pos,
                outerFont(sl.pit(), text.paragraphs()));
 
        return font;
@@ -1465,4 +1488,24 @@ void Cursor::fixIfBroken()
 }
 
 
+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