Abdelrazak Younes wrote:
Dov Feldstern wrote:
I'll add fix this and add it to my suggested patch, I'll also fix the spacing issues that Andre' pointed out, we can wait to hear Elazar's opinion if you want --- but I really think that what I'm suggesting is the way that most bidi users would prefer.

OK.


Here, try the attached patch. I wouldn't commit it like this yet --- I want to unify the two reverseDirections() methods (in Text and in Cursor) --- or at least have one use the other. But this is the functionality which I think we should have.

Dov
Index: src/Text3.cpp
===================================================================
--- src.orig/Text3.cpp  2007-05-09 18:50:13.000000000 +0300
+++ src/Text3.cpp       2007-05-09 18:53:31.000000000 +0300
@@ -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);
@@ -1433,11 +1446,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/Text.h
===================================================================
--- src.orig/Text.h     2007-05-09 18:50:13.000000000 +0300
+++ src/Text.h  2007-05-09 20:00:07.000000000 +0300
@@ -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.cpp
===================================================================
--- src.orig/Cursor.cpp 2007-05-09 19:57:21.000000000 +0300
+++ src/Cursor.cpp      2007-05-09 20:30:36.000000000 +0300
@@ -1345,4 +1345,10 @@
 }
 
 
+bool Cursor::reverseDirections() const
+{
+       return bottom().paragraph().isRightToLeftPar(bv().buffer()->params());
+}
+
+
 } // namespace lyx
Index: src/Cursor.h
===================================================================
--- src.orig/Cursor.h   2007-05-09 19:57:19.000000000 +0300
+++ src/Cursor.h        2007-05-09 19:57:25.000000000 +0300
@@ -309,6 +309,8 @@
        Font getFont() const;
        ///
        bool isRTL() const;
+       ///
+       bool reverseDirections() const;
 };
 
 
Index: src/mathed/InsetMathNest.cpp
===================================================================
--- src.orig/mathed/InsetMathNest.cpp   2007-05-09 19:55:33.000000000 +0300
+++ src/mathed/InsetMathNest.cpp        2007-05-09 20:00:49.000000000 +0300
@@ -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:

Reply via email to