]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Revert 23154.
[lyx.git] / src / Cursor.cpp
index 405d72b4f0af6bc4ea460e155b1506da528329bb..ef62fea62157f49ab01831db0528d1c82222f7ab 100644 (file)
@@ -377,8 +377,6 @@ void Cursor::pushBackward(Inset & p)
 bool Cursor::popBackward()
 {
        BOOST_ASSERT(!empty());
-       //lyxerr << "Leaving inset from in front" << endl;
-       inset().notifyCursorLeaves(*this);
        if (depth() == 1)
                return false;
        pop();
@@ -391,7 +389,6 @@ bool Cursor::popForward()
        BOOST_ASSERT(!empty());
        //lyxerr << "Leaving inset from in back" << endl;
        const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0;
-       inset().notifyCursorLeaves(*this);
        if (depth() == 1)
                return false;
        pop();
@@ -470,6 +467,21 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos)
        // known position around the cursor:
        pos_type known_pos = boundary() ? pos() - 1 : pos();
        
+       // edge case: if we're at the end of the paragraph, things are a little 
+       // different (because lastpos is a position which does not really "exist" 
+       // --- there's no character there yet).
+       if (known_pos == lastpos()) {
+               if (par.isRTL(buf.params())) {
+                       left_pos = -1;
+                       right_pos = bidi.vis2log(row.pos());
+               }
+               else { // LTR paragraph
+                       right_pos = -1;
+                       left_pos = bidi.vis2log(row.endpos() - 1);
+               }
+               return;
+       }
+       
        // Whether 'known_pos' is to the left or to the right of the cursor depends
        // on whether it is an RTL or LTR character...
        bool const cur_is_RTL = 
@@ -484,14 +496,6 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos)
        // determine the other one:
        
        if (known_pos_on_right) {
-               // edge-case: we're at the end of the paragraph, there isn't really any
-               // position any further to the right 
-               if (known_pos == lastpos()) {
-                       right_pos = -1;
-                       left_pos = row.endpos() - 1;
-                       return;
-               }
-               // the normal case
                right_pos = known_pos;
                // *visual* position of 'left_pos':
                pos_type v_left_pos = bidi.log2vis(right_pos) - 1;
@@ -524,14 +528,6 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos)
                }
        } 
        else { // known_pos is on the left
-               // edge-case: we're at the end of the paragraph, there isn't really any
-               // position any further to the left
-               if (known_pos == lastpos()) {
-                       left_pos = -1;
-                       right_pos = row.endpos() - 1;
-                       return;
-               }
-               // the normal case
                left_pos = known_pos;
                // *visual* position of 'right_pos'
                pos_type v_right_pos = bidi.log2vis(left_pos) + 1;
@@ -1768,7 +1764,7 @@ bool Cursor::fixIfBroken()
 }
 
 
-bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
+bool notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
        // find inset in common
        size_type i;
@@ -1780,7 +1776,9 @@ bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
        // 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))
+               Cursor insetPos = old;
+               insetPos.cutOff(i);
+               if (old[i].inset().notifyCursorLeaves(insetPos, cur))
                        return true;
        }