Abdelrazak Younes wrote:
Dov Feldstern wrote:
Dov Feldstern wrote:
Abdelrazak Younes wrote:
Dov Feldstern wrote:
Abdelrazak Younes wrote:

I think it is possible :-)
The problem is simple really and I think you are misleading because you focus on the inset. When you think about it, entering or leaving an inset should not be special; continuous navigation is possible when LTR snippet is embedded in an RTL text: the cursor goes in the opposite direction and then "jumps" to the end of the snippet before going again in the visual direction.


But that's exactly what my patch achieves!

What am I missing?

Really? Maybe it's me who is missing something...

Abdel.


Please try my patch out, and see if the behavior it gives is not what you think should be happening...

The version attached here is the latest one http://permalink.gmane.org/gmane.editors.lyx.devel/83161



Any news? If this behaves the way you want it to, I'd like this to go into beta-3 as well...

Could you please re-generate your patch against current svn (using svn diff). The last one doesn't apply cleanly.

Abdel.



Attached (v2).

I'm also attaching another version of it (v3), which is functionally equivalent, but where I made the reverseDirections method a static method of Bidi. My C++ is quite rusty, so I'm not sure that what I did is correct; or there may be other reasons why you would prefer not to do it that way (for example, the fact that I had to add some includes to Bidi.{cpp,h}). The advantage, though, is that this way everything is in one place, changing between "my approach" and the current approach is just changing from "bottom()" to "innerParagraph()" in that static function.

Dov
Index: src/Cursor.h
===================================================================
--- src/Cursor.h        (revision 18314)
+++ src/Cursor.h        (working copy)
@@ -309,6 +309,8 @@
        Font getFont() const;
        ///
        bool isRTL() const;
+       ///
+       bool reverseDirections() const;
 };
 
 
Index: src/mathed/InsetMathNest.cpp
===================================================================
--- src/mathed/InsetMathNest.cpp        (revision 18314)
+++ src/mathed/InsetMathNest.cpp        (working copy)
@@ -492,7 +492,7 @@
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
-               if (cur.isRTL() )
+               if (cur.reverseDirections())
                        goto goto_char_backwards;
 
 goto_char_forwards:
@@ -515,7 +515,7 @@
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
-               if (cur.isRTL())
+               if (cur.reverseDirections())
                        goto goto_char_forwards;
 
 goto_char_backwards:
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp       (revision 18314)
+++ src/Text3.cpp       (working copy)
@@ -298,6 +298,19 @@
 }
 
 
+bool Text::reverseDirections(Cursor const & cur) const
+{
+       /*
+        * We determine the directions based on the direction of the 
+        * bottom() --- i.e., outermost --- paragraph, because that is
+        * the only way to achieve consistency of the arrow's movements
+        * within a paragraph, and thus avoid situations in which the
+        * cursor gets stuck.
+        */
+       return isRTL(*cur.bv().buffer(), cur.bottom().paragraph());
+}
+
+
 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 {
        LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
@@ -433,7 +446,7 @@
                //lyxerr << BOOST_CURRENT_FUNCTION
                //       << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_CHAR_FORWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirections(cur))
                        needsUpdate |= cursorLeft(cur);
                else
                        needsUpdate |= cursorRight(cur);
@@ -451,7 +464,7 @@
        case LFUN_CHAR_BACKWARD_SELECT:
                //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << 
endl;
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_CHAR_BACKWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirections(cur))
                        needsUpdate |= cursorRight(cur);
                else
                        needsUpdate |= cursorLeft(cur);
@@ -557,7 +570,7 @@
        case LFUN_WORD_FORWARD:
        case LFUN_WORD_FORWARD_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_WORD_FORWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirections(cur))
                        needsUpdate |= cursorLeftOneWord(cur);
                else
                        needsUpdate |= cursorRightOneWord(cur);
@@ -568,7 +581,7 @@
        case LFUN_WORD_BACKWARD:
        case LFUN_WORD_BACKWARD_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_WORD_BACKWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirections(cur))
                        needsUpdate |= cursorRightOneWord(cur);
                else
                        needsUpdate |= cursorLeftOneWord(cur);
@@ -1434,11 +1447,16 @@
 
        case LFUN_FINISHED_LEFT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur 
<< endl;
+               if (reverseDirections(cur)) {
+                       ++cur.pos();
+               }
                break;
 
        case LFUN_FINISHED_RIGHT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur 
<< endl;
-               ++cur.pos();
+               if (!reverseDirections(cur)) {
+                       ++cur.pos();
+               }
                break;
 
        case LFUN_FINISHED_UP:
Index: src/Cursor.cpp
===================================================================
--- src/Cursor.cpp      (revision 18314)
+++ src/Cursor.cpp      (working copy)
@@ -1345,4 +1345,10 @@
 }
 
 
+bool Cursor::reverseDirections() const
+{
+       return bottom().paragraph().isRightToLeftPar(bv().buffer()->params());
+}
+
+
 } // namespace lyx
Index: src/Text.h
===================================================================
--- src/Text.h  (revision 18314)
+++ src/Text.h  (working copy)
@@ -328,6 +328,8 @@
        docstring getPossibleLabel(Cursor & cur) const;
        /// is this paragraph right-to-left?
        bool isRTL(Buffer const &, Paragraph const & par) const;
+       /// should cursor movements be reversed (for bidi)?
+       bool reverseDirections(Cursor const & cur) const;
        ///
        bool checkAndActivateInset(Cursor & cur, bool front);
 
Index: src/Cursor.h
===================================================================
--- src/Cursor.h        (revision 18314)
+++ src/Cursor.h        (working copy)
@@ -307,8 +307,6 @@
        Encoding const * getEncoding() const;
        /// font at cursor position
        Font getFont() const;
-       ///
-       bool isRTL() const;
 };
 
 
Index: src/mathed/InsetMathNest.cpp
===================================================================
--- src/mathed/InsetMathNest.cpp        (revision 18314)
+++ src/mathed/InsetMathNest.cpp        (working copy)
@@ -492,7 +492,7 @@
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
-               if (cur.isRTL() )
+               if (Bidi::reverseDirections(cur))
                        goto goto_char_backwards;
 
 goto_char_forwards:
@@ -515,7 +515,7 @@
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
-               if (cur.isRTL())
+               if (Bidi::reverseDirections(cur))
                        goto goto_char_forwards;
 
 goto_char_backwards:
Index: src/Bidi.h
===================================================================
--- src/Bidi.h  (revision 18314)
+++ src/Bidi.h  (working copy)
@@ -13,6 +13,7 @@
 #define BIDI_H
 
 #include "support/types.h"
+#include "Cursor.h"
 #include <vector>
 
 
@@ -48,6 +49,8 @@
        ///
        void computeTables(Paragraph const & par,
                           Buffer const &, Row const & row);
+       /// Should interpretation of the arrow keys be reversed?
+       static bool reverseDirections(Cursor const & cur);
 private:
        ///
        bool same_direction_;
Index: src/Bidi.cpp
===================================================================
--- src/Bidi.cpp        (revision 18314)
+++ src/Bidi.cpp        (working copy)
@@ -12,6 +12,7 @@
 
 #include "Bidi.h"
 #include "Buffer.h"
+#include "BufferView.h"
 #include "Font.h"
 #include "Row.h"
 #include "LyXRC.h"
@@ -209,4 +210,18 @@
 }
 
 
+bool Bidi::reverseDirections(Cursor const & cur) 
+{
+       /*
+        * We determine the directions based on the direction of the
+        * bottom() --- i.e., outermost --- paragraph, because that is
+        * the only way to achieve consistency of the arrow's movements
+        * within a paragraph, and thus avoid situations in which the
+        * cursor gets stuck.
+        */
+       return cur.bottom().paragraph().isRightToLeftPar(
+                       cur.bv().buffer()->params());
+}
+
+
 } // namespace lyx
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp       (revision 18314)
+++ src/Text3.cpp       (working copy)
@@ -433,7 +433,7 @@
                //lyxerr << BOOST_CURRENT_FUNCTION
                //       << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_CHAR_FORWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (bidi.reverseDirections(cur))
                        needsUpdate |= cursorLeft(cur);
                else
                        needsUpdate |= cursorRight(cur);
@@ -451,7 +451,7 @@
        case LFUN_CHAR_BACKWARD_SELECT:
                //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << 
endl;
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_CHAR_BACKWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (bidi.reverseDirections(cur))
                        needsUpdate |= cursorRight(cur);
                else
                        needsUpdate |= cursorLeft(cur);
@@ -557,7 +557,7 @@
        case LFUN_WORD_FORWARD:
        case LFUN_WORD_FORWARD_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_WORD_FORWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (bidi.reverseDirections(cur))
                        needsUpdate |= cursorLeftOneWord(cur);
                else
                        needsUpdate |= cursorRightOneWord(cur);
@@ -568,7 +568,7 @@
        case LFUN_WORD_BACKWARD:
        case LFUN_WORD_BACKWARD_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == 
LFUN_WORD_BACKWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (bidi.reverseDirections(cur))
                        needsUpdate |= cursorRightOneWord(cur);
                else
                        needsUpdate |= cursorLeftOneWord(cur);
@@ -1434,11 +1434,16 @@
 
        case LFUN_FINISHED_LEFT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur 
<< endl;
+               if (bidi.reverseDirections(cur)) {
+                       ++cur.pos();
+               }
                break;
 
        case LFUN_FINISHED_RIGHT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur 
<< endl;
-               ++cur.pos();
+               if (!bidi.reverseDirections(cur)) {
+                       ++cur.pos();
+               }
                break;
 
        case LFUN_FINISHED_UP:
Index: src/Cursor.cpp
===================================================================
--- src/Cursor.cpp      (revision 18314)
+++ src/Cursor.cpp      (working copy)
@@ -1339,10 +1339,4 @@
 }
 
 
-bool Cursor::isRTL() const
-{
-       return innerParagraph().isRightToLeftPar(bv().buffer()->params());
-}
-
-
 } // namespace lyx

Reply via email to